如何从控制器中定义的标准方法中更新视图?该方法是从我连接的 jquery 插件中调用的。
看法:
@model ViewModel
@Html.EditorFor(model => model.First)
@Html.EditorFor(model => model.Last)
@Html.EditorFor(model => model.Junk)
控制器方法:
// Called from third party jquery plugin
public string DoSomeWorkAndUpdateMyView(string Id)
{
// Get persisted View from dbcontext...
// Create a new Junk object with the new id and add it to the db context
// Update the view with the newly added junk object
ViewModel model = dbContext.GetViewStuff();
model.Junk.Add(new junk);
return View("JunkView", model);
}
用法:
...
onComplete: function (event, queueID, fileObj, response, data)
{
$.ajax(
{ url: '@Url.Action("ProcessForm","Home")',
data: { first: $("#fname").val() },
success: function (data) {
$("#fname").val(data);
}
})
}
...