how to send text box value as parameter on form submit in mvc3 asp.net

纵然是瞬间 提交于 2019-12-22 06:28:33

问题


i have created partial view in MVC3. now i want to send text box value as parameter of form submit on pressing the submit button

my partial view is like

@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" />

 }

and my controller is like

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

回答1:


Simply give your textbox the same name as your action parameter argument:

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

Now inside your controller action you will get the value entered by the user:

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


来源:https://stackoverflow.com/questions/6825985/how-to-send-text-box-value-as-parameter-on-form-submit-in-mvc3-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!