Here is how I'm currently calling the helper in my view (using Razor and C#):
@Html.ListBoxFor(m => m.Measures, new MultiSelectList(Model.Measures, "MsId"),
new Dictionary<string, object> { { "id", "measureId" } })
This works fine setting the "id" in the form element but when I try and do something like this:
@Html.ListBoxFor(m => m.Measures, new MultiSelectList(Model.Measures, "MsId"),
new 开发者_JAVA技巧Dictionary<string, object> { { "id", "measureId" }, { "name", "measureId" } })
The source code generated is still:
<select id="measureId" multiple="multiple" name="Measures">
Any help would be greatly appreciated.
The name is generated from the Expression<Func<TModel, TProperty>>
parameter passed. The name of the property passed is used so in your case m => m.Measures
the name Measures
is used. This is to enable model binding to work when your form is posted to an action.
You can change the name value by change the property name to MeasuresId or if that's not possible you can use the non typed version
@Html.ListBox("measureId", new MultiSelectList(Model.Measures, "MsId"));
pass in:
new { name= "yourname"}
for your html attributes in the overload of ListBoxFor
精彩评论