好的,所以我有这个代码:
public ActionResult Welcome(string name = "", int numTimes = 1)
{
var viewModel = new WelcomeViewModel
{
Message = "Hello " + name,
NumTimes = numTimes
};
return View(viewModel);
}
public class WelcomeViewModel
{
public string Message { get; set; }
public int NumTimes { get; set; }
}
Welcome() 中的视图是:
<h2>Welcome</h2>
<% for(int i = 0; i < Model.NumTimes; i++) {%>
<h3><%: Model.Message; %></h3>
<%} %>
首先,当我运行它时,运行时出现错误 .../Welcome?name=Scott&numtimes=4 在行中说
<h3><%: Model.Message; %></h3>
它期望')'
说明:在编译服务此请求所需的资源期间发生错误。请查看以下特定错误详细信息并适当修改您的源代码。编译器错误消息:CS1026:) 预期
为什么是这样?
其次,这整个模型是什么?它有什么作用?