c# - Render Partial View with Object Model using jquery / Ajax -
my current code looks
<!-- html --> { // code @html.partial("~/views/adminuser/main.cshtml", model.adminusermodel) }
however, need instead ajax call. how do jquery ajax call model included in call?
how ajax call passing id:
$.ajax({ url: "@(url.action("action", "controller", new { id = "----" }))/".replace("----", id), type: "post", cache: false, async: true, success: function (result) { $(".class").html(result); } });
and in controller have action set like
public partialviewresult action(string id) { //build model return partialview("_partialname", model); }
if need pass model controller through ajax, if create jquery object has same fields model , stringify , pass it, come through correctly.
var tosend = {}; tosend.id = id; tosend.name = name;
etc, in ajax call
data: json.stringify(tosend),
Comments
Post a Comment