Asp.net mvc 获取控制器中视图数据的值

Asp.net mvc 获取控制器中视图数据的值,asp.net-mvc,Asp.net Mvc,我做了所有这些,但现在如何在控制器的文本框、密码框等中输入值。我定义了所有必要的方法、框和按钮等,所以唯一的问题是在控制器中获取值,然后将它们发送到模型以访问db数据 .csHtml @using (Html.BeginForm("register","Home", FormMethod.Post, new {id="submitForm"})) { <div> <i>@Html.Label("Name:")</i>

我做了所有这些,但现在如何在控制器的文本框、密码框等中输入值。我定义了所有必要的方法、框和按钮等,所以唯一的问题是在控制器中获取值,然后将它们发送到模型以访问db数据

.csHtml

    @using (Html.BeginForm("register","Home", FormMethod.Post, new {id="submitForm"})) 
    {

    <div>
    <i>@Html.Label("Name:")</i>
       @Html.TextBox("txtboxName")
    </div>

    <div>
    <i>@Html.Label("Email:")</i>
       @Html.TextBox("txtboxEmail")
   </div>

   <div>  
    <i>@Html.Label("Password:")</i>
       @Html.Password("txtboxPassword")
    </div>

    <div>  
     <button type="submit" id="btnSubmit" name="Command" value="Submit">Submit</button> 
    </div>

    }
我有意使用这种编码方式,而不是复杂和先进的方式。请帮助我获取控制器中的值

  [HttpPost]
        public ActionResult register(YOURMODEL model) 
        {
            //db operation
            return View();
        }

注意:确保您的文本框名称应与您的模型名称相同

您应该使用viewmodels。为可发布到动作的视图创建模型。但是,如果您希望继续当前的方法,则需要将控制器操作更改为以下内容:

[HttpPost]
        public ActionResult register(string btnSubmit, string txtboxName, string txtboxEmail, string txtboxPassword) 
        {
            if (command == "submit") 
            {

            }
            return View();
        }
如果这不起作用,您可以使用以下方法进行测试:

    [HttpPost]
    public ActionResult register(FormCollection form) 
    {
        if (command == "submit") 
        {

        }
        return View();
    }

调试时,您可以检查“form”参数,查看表单中是否存在字段,并获取所需参数的正确名称。

否,这是另一种方法,然后我将不得不使用LABELFOR等,但wan可以这样做如果你写`@Html.TextBoxtxtboxEmail`然后自动用值txtboxEmail绑定name&id属性…所以你不必使用textboxfor或LABELFOR为什么不使用model来传递它看起来是正确的,你在调试模式下试过了吗?它有用吗?
    [HttpPost]
    public ActionResult register(FormCollection form) 
    {
        if (command == "submit") 
        {

        }
        return View();
    }