如何更改Action参数的值以在HtmlHelper中自动使用

时间:2018-06-26 09:19:23

标签: c# asp.net-mvc

我有动作

public ActionResult Index(string search)
{ 
    var listingModel = Repository.Search(search); //gets from DB items. Model doesn't include 'serach' string as property or field
    return View("Index", listingModel)
}

“视图”包含带有文本框的过滤器区域(此方法来自辅助方法的扩展方法):

htmlHelper.TextBox("Search", null, htmlAttributesDictionary);

我注意到它会自动将'search'参数的值插入文本框。但是我的问题是我找不到它如何得到的。我看不到.TextBox()助手的源代码。我在htmlHelper.ViewData.Model中找不到此值。我想更改搜索参数的值(我需要保存它为Session并从session获取)。您知道我可以在控制器操作中写些什么,该操作将自动将会话中的值设置为复选框。

我知道我只能使用重定向,但这似乎不是正确的方法。它对我来说不是很漂亮:

public ActionResult Index(string search)
{ 
    search = GetFromSession();
    return RedirectToAction("Index", new {search = search});
    var listingModel = Repository.Search(search); //gets from DB items. Model doesn't include 'serach' string as property or field
    return View("Index", listingModel)
}

0 个答案:

没有答案