When I pass a model to my View in a form, the fields are pre-populated with default values, especially if the model property is an int data type, is there anyway to prevent this?
For example:
Model:
public class MyModel {
[Key]
public int MyKey { get; set; }
public int MyInt { get; set; }
public string MyString { get; set; }
}
Controller:
public class MyController : Controller {
public ActionResult MyAction(int id) {
return View(context.MyModel.Single(x=>x.MyKey == id));
}
}
View:
@model MyNamespace.MyModel
@using(Html.BeginForm())
{
@Html.HiddenFor(x=>x.MyKey)
@Html.EditorFor(x=>x.MyInt)
@Html.EditorFor(x=>x.MyString)
<input type="submit" value="Submit />
}
In the view, the input field for MyInt will be pre-populated with 0 whereas the MyString input will be empty. I want MyInt to be empty too.
Edit:
To clarify, I just wish for the input field to be empty when the page loads and not contain its default value of 0