为什么Request["parameterName"]在视图中返回null?我知道我可以从控制器获取它,但我必须在视图中进行一些检查.我正在使用ASP.NET MVC 3.
请告诉我之间的差异QueryString在Request和RouteData.Values?
我们可以使用它们吗?
例如,我在页面上 http://localhost:1338/category/category1?view=list&min-price=0&max-price=100
在我看来,我想渲染一些形式
@using(Html.BeginForm("Action", "Controller", new RouteValueDictionary { { /*this is poblem place*/ } }, FormMethod.Get))
{
<!--Render some controls-->
<input type="submit" value="OK" />
}
Run Code Online (Sandbox Code Playgroud)
我想要的是view从当前页面链接获取参数值以使用它来构造表单获取请求.我试过@using(Html.BeginForm("Action", "Controller", new RouteValueDictionary { { "view", ViewContext.RouteData.Values["view"] } }, FormMethod.Get))但它没有帮助.
我正在尝试将当前路径导入我的导航控制器,以便在填充导航菜单数据时运行比较.
我的链接对象是这样的:
public class StreamNavLinks
{
public string Text { get; set; }
public RouteValueDictionary RouteValues { get; set; }
public bool IsSelected { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在母版页中,我试图将当前路径传递给导航控制器,如下所示:
<% Html.RenderAction(
"MenuOfStreamEntries", // action
"Nav", // controller
new { // parameters for action
currentStreamUrl = "Blog",
currentRoute = ViewContext.RouteData } // get route data to compare in controller
); %>
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是我无法弄清楚如何获取任何数据currentRoute.获取价值的最佳方法是什么currentRoute?
我试过这样的语法:
currentRoute.Values.routevaluename
Run Code Online (Sandbox Code Playgroud)
和
currentRoute.Values[0]
Run Code Online (Sandbox Code Playgroud)
但我似乎无法让它发挥作用.
我也尝试将此代码放入导航控制器的操作中:
var current = RouteData["streamUrl"];
Run Code Online (Sandbox Code Playgroud)
和
var current = …Run Code Online (Sandbox Code Playgroud)