Question

I am very new to MVC i am trying to create simple login form in MVC 2

This is my View:

<form id="LoginForm" runat="server">
    <p>
        <%=Html.TextBoxFor(Model=>Model.UserName) %>
        <%=Html.ValidationMessageFor(Model=>Model.UserName) %>
    <p>
</form>

Here it creates Textbox at runtime. So my question is how to create simple html input without use of razor ??

I have tried to use this but it does not work completely

<input type="text" name="<%=Html.TextBoxFor(Model=>Model.UserName) %>" 
     value="<%=Html.ValidationMessageFor(Model=>Model.UserName) %>" />
Was it helpful?

Solution

You should not use runat="server" in an ASP.NET MVC application. That's the first thing you should remove from your form tag. If you don't want to use the built-in TextBoxFor helper to generate an input field you could always write the markup directly:

<input type="text" name="username" value="<%= Model.UserName %>" />

but usually it is better to use the helpers as they will take care of things like validation and generate proper markup for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top