javascript - How to update partialview on ajax call -
we having situation stuck in ajax:
this how use partial our view:
<div class="mycheck check-come" id="checklist"> @if (model.curtodo.trntodolist != null) {<ul> @foreach (var item in model.curtodo.trntodolist) { <li>@html.partial("todochecks", item)</li> } </ul> } </div>
and being called using ajax this:
$("#curtodo_todotitle").blur(function () { var formdata = new formdata($('#form0').get(0)); // serialize form formdata.append('buttontype', 'save'); // add additional properties $.ajax({ url: "/tasktd/postit", type: "post", data: formdata, datatype: "json", processdata: false, contenttype: false }).success(function (model) { $("#curtodo_todoid").val(model.curtodo.todoid); $("#curtodo_todotitle").val(model.curtodo.todotitle); $("#curtodo_tododesc").val(model.curtodo.tododesc); $(".panel-header").addclass("show"); //$(".check-come").addclass("show"); $("#checklist li").html(model); $(".mycheck").show(); }); });
we have partial view active tasktd created shown in above code of jquery. nothing. @ other end revisit page same created id querystring, loads partial view.
we want show partial view data saved main view.
and rendered snippet this:
<div class="mycheck check-come" id="checklist"> </div>
note, there no html generated within it.
controller:
public actionresult index(int tdid = 0) { todolist tdl = new todolist(); todo t = new todo (); // todotrn ttrn = new todotrn(); list<todo> tds = todo.load(); tdl.todos=tds; userview u = new userview(); t.createdby = user.identity.getuserid(); u.userid = user.identity.getuserid(); u.username = user.identity.name; // tdl.tditems.createdby = convert.toint32(userid); if (tdid != 0) { t = t.loadtodo(tdid); tdl.curtodo=t; todotrn trn = new todotrn(tdid); list<todotrn> tlist = new list<todotrn>(); tlist.add(trn); tdl.curtodo.trntodolist = tlist; //tdl.curtodotrn = ttrn; tdl.usermodel = u; // t.usermodel = u; } else { tdl.curtodo=t; // tdl.curtodotrn = ttrn; tdl.usermodel = u; // t.usermodel = u; } return view(tdl); }
saving action
public async task<actionresult> postit(todolist td, string buttontype) { if (buttontype == "delete") { td.curtodo.delete(); todo tt = new todo(); td.curtodo = tt; return json(new { redirecturl = url.action("index", "tasktd"), isredirect = true }); } else if (buttontype == "prioritize") { td.curtodo.prioritize=td.curtodo.toggleprioritize(); } else if (buttontype == "save") { var errors = modelstate.values.selectmany(v => v.errors); modelstate.remove("todoid"); modelstate.remove("todotrnid"); if (modelstate.isvalid) { var t = await td.curtodo.save(); if (td.curtodo.trntodolist==null) { try { todotrn trn = new todotrn(td.curtodo.todoid); list <todotrn> tlist= new list<todotrn>(); tlist.add(trn); td.curtodo.trntodolist = tlist; } catch(exception ex) { } } return json(td, jsonrequestbehavior.allowget); } } else if (buttontype == "checksave") { var errors = modelstate.values.selectmany(v => v.errors); // modelstate.remove("todoid"); modelstate.remove("todotrnid"); if (modelstate.isvalid) { //td.curtodotrn.todoid = td.curtodo.todoid; //var t = await td.curtodotrn.todotrnsave(td.curtodotrn); return json(td, jsonrequestbehavior.allowget); } } return json("oops! please enter required values"); }
just use normal actionresult
[httppost]
, can use renderaction in razer instead of partial. normal ajax call , use $("#").html(retval);
Comments
Post a Comment