开发者

How to use JQuery Dialog to post sub-set of data on form and refresh parent in MVC?

I have a JQuery dialog which is rendered in a partial view within a main view.

I want the form to post the whole parent page back so it is refreshed on submitting the data. However, the model that I use is stored in a class off the main model class e.g. MainModel.Current

At the top of the dialog I have the link to the MainModel (@model...) Then in the helpers use lambda like so: m => m.Current.Field

In the controller, the model being passed into the parameter of the function is null? Is there any reason for this? How do I go about passing in a different model or a 开发者_如何学编程subset of the model and refresh the parent. Its a nightmare in mvc.

Updated

In main view:

@model MyProject.ParentModel
...
Html.RenderAction("AddChildData");

In partial view:

@model MyProject.ParentModel

@Html.TextBoxFor(model => model.ChildData.Name)
@Html.ValidationMessageFor(model => model.ChildData.Name)

In controller:

 [HttpPost]
 public ActionResult AddItem(ParentModel parentModel)
 {
    myService.AddItem(parentModel.childData); <-- parentModel is null
    return RedirectToAction("Index");
 }


Turns out this was because I had a nested form and this was intercepting the model data of the parent form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜