Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HtmlFieldPrefix not mapping to model

Hello I have recently began work on a largely JQuery/JQueryUI based ASP .Net website. The idea was to have only one page and to have the rest of the content be dynamic, etc loaded in through dialogs and ajax.

The problem is however when a Create & a Edit form for the same model are open in dialogs at the same time some JQueryUI widgets such as the DatePicker stop working as the forms cause the DOM to have duplicate id's on the fields which are present in both.

So I tried using this code on the controller:

ViewData.TemplateInfo.HtmlFieldPrefix = "Create"; // or Edit etc

This worked to fix the DatePicker problem, but the fields no longer mapped to the model when they were posted back to the controller.

Does anyone know how to fix this?

like image 536
Alex Hope O'Connor Avatar asked Feb 25 '11 01:02

Alex Hope O'Connor


1 Answers

You could try specifying the same prefix when binding back:

[HttpPost]
public ActionResult Create([Bind(Prefix = "Create")] CreateViewModel model)
{
    ...
}
like image 97
Darin Dimitrov Avatar answered Oct 08 '22 21:10

Darin Dimitrov