I'm using MVC4.
I have the following element in Razor View
:
@Html.DropDownListFor(m => m.Planning_Control_Resi1, Model.Planning_Control_Resi1List)
and in Model
the following functions:
public struct RugItem
{
public float value { get; set; }
public string name { get; set; }
}
public float Planning_Control_Resi1 { get; set; }
public IEnumerable<SelectListItem> Planning_Control_Resi1List
{
get
{
List<RugItem> listItems = new List<RugItem>();
float valuef = 0.05f;
for (int i = 0; i <= 20; i++)
{
listItems.Add(new RugItem
{
name = valuef + "",
value = valuef
});
valuef += 0.05f;
}
return new SelectList(listItems, "value", "name");
}
}
The full form is:
@using (Html.BeginForm("RunRug", "Impressions", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.LabelFor(m => m.Planning_Control_Resi1, "Planning_Control_Resi1")
@Html.DropDownListFor(m => m.Planning_Control_Resi1, Model.Planning_Control_Resi1List)
<br />
<input type="hidden" name="cookie_token" id="cookie_token" />
<input type="submit" value="Run Rug" />
}
The HTML produced by the previous code is :
<option value="0,05">0,05</option>
<option value="0,1">0,1</option>
<option value="0,15">0,15</option>
<option value="0,2">0,2</option>
My regional settings for decimal symbol is ,
and I can't change it. The problem is that the value isn't sent back to controller because it can't convert string format ("0,05" to double).
How can I convert the value from options from string to double in a DropDownListFor element?
Thank you,