【问题标题】:how to send text box value as parameter on form submit in mvc3 asp.net如何在 mvc3 asp.net 中将文本框值作为参数发送到表单提交
【发布时间】:2011-07-26 06:09:56
【问题描述】:

我在 MVC3 中创建了局部视图。现在我想在按下提交按钮时发送文本框值作为表单提交的参数

我的部分观点是这样的

@using (Html.BeginForm("Searching", "AccountManager", FormMethod.Post, new { name ="Wat should i put here" }))
 {

   <input id="account" type="text" class="s" />
   <input id="Search" type="submit" class="b" value="hi" />

 }

我的控制器就像

 public viewResult Searching(string name)
 {
   // bussiness logic
   return view();
 }

【问题讨论】:

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


    【解决方案1】:

    只需将您的文本框命名为与您的操作参数参数相同的名称:

    @using (Html.BeginForm("Searching", "AccountManager")
    {
        <input id="account" type="text" name="name" class="s" />
        <input id="Search" type="submit" class="b" value="hi" />
    }
    

    现在在您的控制器操作中,您将获得用户输入的值:

    public ActionResult Searching(string name)
    {
        // bussiness logic
        return View();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-19
      • 1970-01-01
      • 1970-01-01
      • 2014-02-10
      • 2023-03-05
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      相关资源
      最近更新 更多