【问题标题】:MVC how can i post a form without using a modelMVC如何在不使用模型的情况下发布表单
【发布时间】:2014-10-21 09:42:57
【问题描述】:

我想知道如何在不使用模型绑定到视图的情况下在 mvc 4 中汇总表单。

有人可以演示一下吗?以及如何在控制器中使用该表单?

【问题讨论】:

    标签: forms model-view-controller


    【解决方案1】:

    在没有任何类型的模型绑定的情况下使用表单非常容易。

    使用@using(Html.BeginForm()){ ... } 或纯 html 进行简单设置。

    <form id="myForm" action="/ControllerName/ActionName" method="Post">
    
        <input type="text" name="foo" value="FOOOO" />
        <input type="text" name="bar" value="Baaaar" />
        <button type="submit">Submit</button>
    
    </form>
    

    当您将其发布到 ActionResult 时,您的操作结果只需设置为接受一个名为 foo 的字符串值和一个名为 bar 的字符串值

    [HttpPost]
    public ActionResult ActionName(string foo, string bar){
        // your code here
        return View();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-10
      • 2020-09-09
      • 2012-07-24
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多