Search code examples
asp.net-mvc-3razor-2

Html helper for textbox using asp.net mvc3


I am trying to replace the following html textbox using html helpers for asp.net mvc3 application.

<input name="Name" id="add-student-name" type="text" maxlength="50" />

I tried with the following but on rendering I found it is not matching with the above html markup.

@Html.TextBox("Name", new {id="add-student-name", maxlength="50"})

Can anyone help me to resolve the above issue?


Solution

  • Add null as the second argument (your html attributes go in as the third argument)

    @Html.TextBox("Name", null, new {id="add-student-name", maxlength="50"})
    

    Been a few years since I did asp.net but I'm pretty sure that'll turn out to be your issue.