I have an extremely simple page. It has a few devexpress textboxs and a devexpress button.
These textboxs are bound to specific fields within my model.
Upon clicking the button it shoots over to my action, upon reviewing the model in my action my fields are empty. I initially had this working perfectly with @Html.TextBoxFors. Upon adding in the Devexpress textboxs and textboxfors nothing works.
I have reviewed stackoverflow and have found no solution, although I have found a similar question, essentially identical but if I need to start a bounty I would rather do it on my own question, as far as code is concerned mine is very very similar to the one below. :
MVC 3 DevExpress – Model Returned to Controller is Empty
I have also reviewed devexpress’s website and found this. :
http://www.devexpress.com/Support/Center/Example/Details/E2886
The above is essentially a demo of how to properly do this. My project and the other stackoverflow user’s code are pretty much exactly the same as this.
I am assuming others have had this issue. I have been attempting to get this to work for weeks now and still have had no luck. Any ideas are greatly appreciated.
Code
View
@inherits System.Web.Mvc.WebViewPage<MyModel>
@using DevExpress.Web.ASPxEditors;
@using (Html.BeginForm("MyModelSave", "Home", FormMethod.Post))
{
<div>
@Html.DevExpress().TextBox(settings =>
{
settings.Name = "txtId";
settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
}).Bind(Model.Id).GetHtml()
</div>
<div>
@Html.DevExpress().TextBox(settings =>
{
settings.Name = "txtName";
settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
}).Bind(Model.Name).GetHtml()
</div>
<div>
@Html.DevExpress().Button(s =>
{
s.Name = "btnSave";
s.Images.Image.Url = "~/Images/save.png";
s.Text = string.Empty;
s.ToolTip = "Save";
s.UseSubmitBehavior = true;
}).GetHtml()
</div>
}
Action
[HttpPost]
public ActionResult MyModelSave([ModelBinder(typeof(DevExpressEditorsBinder))]MyModel modelTest)
{
if (!ModelState.IsValid)
{
return View();
}
else
{
//Work with model
return View();
}
}
For the model binding your html input (TextBox) names and your model property names should match.
So your
DevExpress().TextBoxs need to have the samesettings.Names as your model properties: