2012-06-04 68 views
1

我有這個在我看來:如何完成剃鬚刀部分?

<input id="@Html.TextBoxFor(m => m.UserName)" type="text" placeholder="Username" autofocus required> 
    <input id="(@Html.PasswordFor(m => m.Password))" type="password" placeholder="Password" required> 

它的工作,但我的結果是 enter image description here

我在做什麼錯?

回答

4

要麼你想要把HTML作爲標籤:

<input id="UserName" type="text" placeholder="Username" value="@Model.UserName" autofocus required /> 
<input id="Password" type="password" placeholder="Password" value="@Model.Password" required /> 

或者讓剃鬚刀爲你做它:

@Html.TextBoxFor(m => m.UserName); 
@Html.PasswordFor(m => m.Password); 

你是混合在一起的。你的例子從純HTML開始,然後它找到了在純HTML內部呈現另一個輸入標籤的Razor命令。當您需要返回模型類型時,優先使用Razor代碼。