Use código duro en el motor de visualización MVC3 Razor

I have the following Razor code:

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

I would like to hard code the value 1001 as a default for the Input field. I have tried [model.accountcode ="1001"] que no funciona.

Por favor explique con código de ejemplo.

preguntado el 04 de julio de 12 a las 04:07

2 Respuestas

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)

Respondido 04 Jul 12, 04:07

If you want to display some value directly in the textbox then you should try

@Html.TextBox("AccountCode", "1001")

Respondido 04 Jul 12, 04:07

Actually i want don't display control in my browse but i want to save "accountCode = 1001" - Mohamed Faruk

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.