Use hard code in MVC3 Razor view engine


I have the following Razor code:

    <div class="editor-label">
         @Html.LabelFor(model => model.AccountCode)
    <div class="editor-field">
         @Html.EditorFor(model => model.AccountCode)

I would like to hard code the value 1001 as a default for the Input field. I have tried [model.accountcode ="1001"] which does not work.

Please explain with example code.

If you want to set a value in the model, that should be done in the controller...

public ActionResult MyAction()
    var myModel = new ModelClass();
    myModel.AccountCode = 1001;
    return View("MyViewName", myModel);

Then use the normal syntax in Razor:

@Html.TextBoxFor(m => m.AccountCode)

Or if you just want a hidden parameter:

@Html.HiddenFor(m => m.AccountCode)