jquery - Using the $.ajax to get a partial view -
jquery - Using the $.ajax to get a partial view -
i'm using asp.net mvc 3 build application, i'm having problem when trying partial view; here's code
the view :
@{while (model.read()) { <ul class="tabs"> <li id="general" class="active">informations générals</li> <li id="contact">contacts</li> </ul> <div id="contentdetail"> <div><b>description :</b> @model["description"]</div> <div><b>activity :</b> @model["activity"]</div> </div> <script type="text/javascript"> $("#contact").click(function () { $.ajax({ url: '@url.content("~/company/contacts/")', type: 'get', data: json.stringify('@model["id"]'), datatype: 'json', contenttype: 'application/json; charset=utf-8', success: function (data) { $('#contentdetail').replacewith(data); }, error: function (request, status, err) { alert(status); alert(err); } }); }); </script> }
}
the controller :
public actionresult contacts(int id) { homecoming partialview("_contacts", getcontactdetails(id)); }
"_contacts" partial view, it's typed.
home clear, ^^
the next wrong:
data: json.stringify('@model["id"]')
replace real json object:
data: json.stringify(@(html.raw(json.encode(new { id = model["id"] }))))
or with:
data: json.stringify({ id: "@model["id"]" })
which when rendered in final markup this:
data: json.stringify({ id: "123" })
jquery asp.net-mvc-3 partial-views
Comments
Post a Comment