将SearchBox值传递给MVC4中的ActionResult方法 [英] Passing SearchBox value to ActionResult Method in MVC4
本文介绍了将SearchBox值传递给MVC4中的ActionResult方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图根据SearchKey搜索给定列表。我的表单上有多个按钮,所以要处理这个,我使用了ActionNameSelectorAttribute。但在使用它之后,SearchBox的值不会在ActionResult方法中传递。
I trying to Search a given list according to give "SearchKey". I have multiple buttons on my form, So to handle this i have used "ActionNameSelectorAttribute". But after using it, Value of SearchBox is not passed in ActionResult Method.
[HttpPost]
[MultiButton(MatchFormKey = "action", MatchFormValue = "Search")]
public ActionResult Serach(string SearchKey)
{
ProjectUtility OProjectUtility = new ProjectUtility();
IEnumerable<Project> obj = OProjectUtility.SearchByKey(SearchKey);
return View(obj);
}
SearchKey值为空。
On View我有TextBox和一个按钮。
请帮忙!
the "SearchKey" value is null.
On View I have TextBox and a button.
Please help!
推荐答案
我认为你不能直接得到文本框值,可以使用Formcollection类,在这个类中你将获得表格中所有控件的值。
I think you cant get the textbox value directly,can use Formcollection class, in this class you will get value of all the controls present on form.
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
using (LoginModelDataContext objLoginModelDataContext = new LoginModelDataContext())
{
string Isupdate = collection["ckbStatus"];
if (Isupdate == "true,false")
{
objLoginModelDataContext.insertStatusOfGoal(id);
}
var recordToUpdate = objLoginModelDataContext.GoalDetails.Single(m => m.Id == id);
TryUpdateModel(recordToUpdate);
if (ModelState.IsValid)
{
objLoginModelDataContext.SubmitChanges();
return RedirectToAction("Index");
}
return View(recordToUpdate);
}
}
在此代码中我得到复选框的值,在以同样的方式你可以得到文本框的价值。
希望这会有所帮助
In this code i am getting the value of checkbox,in the same way you can get the value of textbox.
hope this will help
这篇关于将SearchBox值传递给MVC4中的ActionResult方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文