如何将当前参数传递给 MVC5 C# 中的 Url.Action?

如何将当前参数传递给 MVC5 C# 中的 Url.Action?


视图模型:


IndexViewModel

 ->SubViewModel

   ->Option1

参数为 routeValues 中的 SubViewModel.Option1。


看法:


Url.Action("Index", this.ViewContext.RouteData.Values)

即使存在路由值,这也不会返回任何路由。


吃鸡游戏
浏览 154回答 1
1回答

守候你守候我

我通过使用这个扩展找到了解决方案:public static class NvcExtension{&nbsp; &nbsp; public static IDictionary<string, object> ToDictionary(this NameValueCollection col)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; IDictionary<string, object> dict = new Dictionary<string, object>();&nbsp; &nbsp; &nbsp; &nbsp; foreach (var k in col.AllKeys)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dict.Add(k, col.GetValues(k).FirstOrDefault());&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return dict;&nbsp; &nbsp; }}看法:Url.Action("Index", new RouteValueDictionary(this.Request.QueryString.ToDictionary()))
打开App,查看更多内容
随时随地看视频慕课网APP