我可以声明一个名为Model的变量

时间:2014-11-19 18:17:41

标签: c# asp.net-mvc asp.net-mvc-3

我试图在MVC模型中声明一个名为" Model"的变量。并在aspx视图中使用它 我已为此编写了示例代码。 模型:

public int id { get; set; }
public bool Model { get; set; }

视图:

      <%@Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.account>"  %>
      <% using (Html.BeginForm("modelsubmit","Home"))
      {%>
       <%: Html.EditorFor(x =>x.id) %>
       <%: Html.EditorFor(x =>x.Model) %>
Action :-

       var model = new account();
              model.id = 1;
               model.Model = true;
             return View(model);

发布方法:

[HttpPost]
public ActionResult modelsubmit(account acc)
{
    if(acc.Model == true){}
    return Json(null);
}

但它让我误以为&#34;参数不能为空&#34;。 它不会为任何其他变量抛出错误。 我甚至在初始化模型时指定变量的值。

0 个答案:

没有答案
相关问题