How to access model in jquery

How to access model in jquery

The question here is very simple

This is my view

<%@ Control Language="C#"      Inherits="System.Web.Mvc.ViewUserControl<GetmoreRevamp.BAL.Product>" %> <link href="<%=Url.Content("~/Content/AddToCart.css")%>" rel="stylesheet"       type="text/css" /> <link href="<%=Url.Content("~/Scripts/jquery-1.4.1.js")%>" type="text/javascript" />  <script type="text/javascript">     function submitForm(formData) {         var tdata = $(formData).serialize();         $.ajax({             type: "POST",             url: '<%= Url.Action("AddToCart","Cart")%>',             data: tdata,             contentType: 'application/json; charset=utf-8',             datatype: "json",             success: function(result) { success(result); }         });         return false;     }     function success(result) {         alert("success:" + result.success);     }   </script>  <% using (Html.BeginForm("AddToCart", "Cart ", Model, FormMethod.Post,              new { onsubmit = "return submitForm('this');" })) {%> <div class="prishosbtn">     <a rel="prettyPhoto" href="" id="buy">         <%Response.Write("<input type=\"image\" class=\"imgClass\" alt=\"" +                          (Model != null && Model.ProductName != null ?                                        Model.ProductName : "KOEB") + "\" src=\"" +                         Url.Content("~/pics/undersider/listevisning/kob-knap.png") +                           "\" id=\"ImageButton\" name=\"ImageButton\" />");%>     </a> </div> <%}%> 

This is my controller

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using GetmoreRevamp.WEB.Models; using GetmoreRevamp.WEB.Models.BLLModels; using System.Web.Security; using System.Security.Principal; using GetmoreRevamp.WEB.Utilities; using GetmoreRevamp.BAL;  namespace GetmoreRevamp.WEB.Controllers {     public class CartController : Controller     {         //         // GET: /Cart/         public ActionResult Index()         {             return View("Cart");         }          [AcceptVerbs(HttpVerbs.Post)]         public ActionResult AddToCart(Product product)         {             JsonResult result = new JsonResult();             OrderHeader orderHeader =                  Session[Constants.CurrentlySessionOrderHeader] as OrderHeader;             if (orderHeader == null)             {                 orderHeader = new OrderHeader();             }             if (product != null && product.ProductGuid != null &&                 string.Equals(product.ProductGuid, string.Empty))             {                 orderHeader.AddOrderLineItem(1, product);                 orderHeader.Calculate();                 Session[Constants.CurrentlySessionOrderHeader] = orderHeader;                 //Default redirection Must be changed when actual view is created                 result.Data = true;             }             else             {                 //Default redirection Must be changed when actual view is created                 result.Data = false;             }             return result;         }     } } 

"Product" is defined in bal. Product contains other business entities. What i simply want to do is to access the model with which view is binded in jquery and then post it to my action method in cart controller. i do not want to post the id of product. I want to post the actual model via jquery to my action method. I am a total newbie in this. so any help and most imp simple solution will be preferred

Value from Hidden Input field as an Actionlink Parameter


How to send jQuery $.get so the Model Binder can bind a string to a parameter?
MVC matches field names to the business object in the action method, so if Product has a ProductID field, there should be a:. Adding check boxes to each row on MVCcontrib Grid
declaration, or use the TextBoxFor method in MVC 2. Html Helpers generates ID from model properties. How do I target 1 particular element with JavaScript and CSS if many elements have the same ID? I'm pretty sure that's still how it works even when posting using JQuery. Which is the preferred method of starting a form using HTML helpers? The model binder handles the process of taking the form fields and passing them to the product object. mvc viewdata tempdata variable But, all of the fields have to be within the form this you are posting to the server, or you have to explicitly pass the parameters where you pass the tdata variable.... Linq-To-Sql, MVC, Enumerable results with Distinct query HTH.. Add another propertymapping? (AutoMapper)

68 out of 100 based on 63 user ratings 578 reviews