문제

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) %>" />
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top