ASP.NET MVC4 HtmlHelper 输出额外不需要的标记
ASP.NET MVC4 HtmlHelper outputting extra unwanted markup
基本上,我看到的是“;”突然出现。我不知道它来自哪里,也没有明显的来源。
我在这个测试站点没有javascript或css。
我的模型:(不重要)
public class RegisterAccountViewModel
{
public long? Id { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
[Required]
public string Email { get; set; }
[Required]
public string PhoneNumber { get; set; }
[Required]
public string AccountType { get; set; }
public string OrganizationName { get; set; }
}
视图(Test.cshtml):
@model RegisterAccountViewModel
@{Layout = null;}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Test</title>
</head>
<body>
<div>
<input type="text" placeholder="FirstName"/>
<br/>
@Html.TextBoxFor(m => m.LastName, new {placeholder = "Last Name" });
</div>
</body>
</html>
控制器
public class LoginController : Controller
{
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult Test()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Register(RegisterAccountViewModel model)
{
return null;
}
}
什么给了?
为了确保这对我来说没有任何问题,我使用默认模板创建了一个新的 mvc 站点并添加了一个文本框;结果与下图相同
删除 LastName TextBoxFor.
末尾的分号 ;
@Html.TextBoxFor(m => m.LastName, new {placeholder = "Last Name" }); //<-- remove this semicolon
注意:- 在 razor(MVC) 语法中 ;
仅当您在 @{}
中编写一些 C# 代码时才需要,没有必要;
在 html 辅助扩展方法的末尾。
您必须删除“;”在您视图的最后一行:
@Html.TextBoxFor(m => m.LastName, new {placeholder = "Last Name" })
基本上,我看到的是“;”突然出现。我不知道它来自哪里,也没有明显的来源。
我在这个测试站点没有javascript或css。
我的模型:(不重要)
public class RegisterAccountViewModel
{
public long? Id { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
[Required]
public string Email { get; set; }
[Required]
public string PhoneNumber { get; set; }
[Required]
public string AccountType { get; set; }
public string OrganizationName { get; set; }
}
视图(Test.cshtml):
@model RegisterAccountViewModel
@{Layout = null;}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Test</title>
</head>
<body>
<div>
<input type="text" placeholder="FirstName"/>
<br/>
@Html.TextBoxFor(m => m.LastName, new {placeholder = "Last Name" });
</div>
</body>
</html>
控制器
public class LoginController : Controller
{
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult Test()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Register(RegisterAccountViewModel model)
{
return null;
}
}
什么给了?
为了确保这对我来说没有任何问题,我使用默认模板创建了一个新的 mvc 站点并添加了一个文本框;结果与下图相同
删除 LastName TextBoxFor.
末尾的分号;
@Html.TextBoxFor(m => m.LastName, new {placeholder = "Last Name" }); //<-- remove this semicolon
注意:- 在 razor(MVC) 语法中 ;
仅当您在 @{}
中编写一些 C# 代码时才需要,没有必要;
在 html 辅助扩展方法的末尾。
您必须删除“;”在您视图的最后一行:
@Html.TextBoxFor(m => m.LastName, new {placeholder = "Last Name" })