废话不多说,直接讲我的思路:
利用Ajax+PartialView时间局部刷新。
首先在页面上引用了一个PartialView,,当用Ajax更新数据时需要同时更新整个PartialView内容。
Ajax代码:
$.ajax({ url: "url",type: "Post",data: {"sectionid": sectionId,"questions": ids.join(",")},success: function (data) {//TODO:处理添加新问卷成功后的事件$("Selector").html(data);},error: function (XMLHttpRequest, textStatus, errorThrown) {alert("保存失败:" + errorThrown);}});
后台C#代码:
[HttpPost]public ActionResult UpdateSection(int sectionid, string questions){try{//更新PartialViewreturn PartialView("ViewSection", newSection);}catch (Exception exp){throw exp;}}就这么简单,根本不需要拼接字符串什么的。
让我们将事前的忧虑,换为事前的思考和计划吧!