In Asp.NET MVC, how do you make your controller return a view with a query string?
在Asp.NET MVC中,如何让控制器返回带有查询字符串的视图?
thanks
3 个解决方案
#1
It might be better if you post what you are trying to accomplish. The simple answer is that you can't, the querystring is part of the request so if you wanted to do that you would need to redirect to your view with the querystring as part of the URL... but it sounds like you are perhaps trying to use the querystring to pass data to the view? If so you are much better off using ViewData.
如果你发布你想要完成的东西可能会更好。简单的答案是,你不能,查询字符串是请求的一部分,所以如果你想这样做,你需要使用查询字符串作为URL的一部分重定向到你的视图...但听起来你可能是试图使用查询字符串将数据传递给视图?如果是这样,你最好使用ViewData。
#2
This should get you started with returning views. And this tutorial should show you how params can be passed into actions to generate specific results.
这应该让您开始返回视图。本教程应该向您展示如何将params传递给动作以生成特定结果。
#3
Use this
return RedirectToAction("AmendAbsence", new RouteValueDictionary (new { Controller ="Absence", Action="AmendAbsence", Id=id }));
Configure your Global.asmx appropriately
适当配置Global.asmx
thanks
#1
It might be better if you post what you are trying to accomplish. The simple answer is that you can't, the querystring is part of the request so if you wanted to do that you would need to redirect to your view with the querystring as part of the URL... but it sounds like you are perhaps trying to use the querystring to pass data to the view? If so you are much better off using ViewData.
如果你发布你想要完成的东西可能会更好。简单的答案是,你不能,查询字符串是请求的一部分,所以如果你想这样做,你需要使用查询字符串作为URL的一部分重定向到你的视图...但听起来你可能是试图使用查询字符串将数据传递给视图?如果是这样,你最好使用ViewData。
#2
This should get you started with returning views. And this tutorial should show you how params can be passed into actions to generate specific results.
这应该让您开始返回视图。本教程应该向您展示如何将params传递给动作以生成特定结果。
#3
Use this
return RedirectToAction("AmendAbsence", new RouteValueDictionary (new { Controller ="Absence", Action="AmendAbsence", Id=id }));
Configure your Global.asmx appropriately
适当配置Global.asmx
thanks