码迷,mamicode.com
首页 > Web开发 > 详细

MVC中的RedirectToRouteResult方法+MVC中一个Action转到另一个Action(一个页面转到另一个页面)需要值提示某值为空时解决方法

时间:2021-01-26 12:22:20      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:ring   values   exce   direct   action   控制   value   cte   base   

首先明白返回的方法(RedirectToRouteResult),主要讲两种他的重载,其它请看后面代码

1.

protected internal RedirectToRouteResult RedirectToAction(string actionName);
这个比较简单直接上代码
 1  public ActionResult Delete(int id)
 2         {
 3            
 4             //跳转到Index页面
 5             return RedirectToAction("Index");
 6         }
 7  public ActionResult Index()
 8         {
 9 
10          
11             return View();
12             
13         }

 

还有一种重载是可以跨controller的后面有需要的去看



2.
protected internal RedirectToRouteResult RedirectToActionPermanent(string actionName, object routeValues);

这种主要运用于返回Action需要值得情况
 1 public ActionResult CreateKinds(int oneKind,GoodsKind model)
 2         {
 3             
 4             return RedirectToAction("Kinds", new { id=你对应的值});
 5         }
 6 public ActionResult Kinds(int id)
 7         {
 8 
 9 
10             return View();
11         }

 

3
其它重载
  1         //
  2         // 摘要: 
  3         //     使用操作名称重定向到指定的操作。
  4         //
  5         // 参数: 
  6         //   actionName:
  7         //     操作的名称。
  8         //
  9         // 返回结果: 
 10         //     重定向结果对象。
 11         protected internal RedirectToRouteResult RedirectToAction(string actionName);
 12         //
 13         // 摘要: 
 14         //     使用操作名称和路由值重定向到指定的操作。
 15         //
 16         // 参数: 
 17         //   actionName:
 18         //     操作的名称。
 19         //
 20         //   routeValues:
 21         //     路由的参数。
 22         //
 23         // 返回结果: 
 24         //     重定向结果对象。
 25         protected internal RedirectToRouteResult RedirectToAction(string actionName, object routeValues);
 26         //
 27         // 摘要: 
 28         //     使用操作名称和路由字典重定向到指定的操作。
 29         //
 30         // 参数: 
 31         //   actionName:
 32         //     操作的名称。
 33         //
 34         //   routeValues:
 35         //     路由的参数。
 36         //
 37         // 返回结果: 
 38         //     重定向结果对象。
 39         protected internal RedirectToRouteResult RedirectToAction(string actionName, RouteValueDictionary routeValues);
 40         //
 41         // 摘要: 
 42         //     使用操作名称和控制器名称重定向到指定的操作。
 43         //
 44         // 参数: 
 45         //   actionName:
 46         //     操作的名称。
 47         //
 48         //   controllerName:
 49         //     控制器的名称
 50         //
 51         // 返回结果: 
 52         //     重定向结果对象。
 53         protected internal RedirectToRouteResult RedirectToAction(string actionName, string controllerName);
 54         //
 55         // 摘要: 
 56         //     使用操作名称、控制器名称和路由值重定向到指定的操作。
 57         //
 58         // 参数: 
 59         //   actionName:
 60         //     操作的名称。
 61         //
 62         //   controllerName:
 63         //     控制器的名称
 64         //
 65         //   routeValues:
 66         //     路由的参数。
 67         //
 68         // 返回结果: 
 69         //     重定向结果对象。
 70         protected internal RedirectToRouteResult RedirectToAction(string actionName, string controllerName, object routeValues);
 71         //
 72         // 摘要: 
 73         //     使用操作名称、控制器名称和路由字典重定向到指定的操作。
 74         //
 75         // 参数: 
 76         //   actionName:
 77         //     操作的名称。
 78         //
 79         //   controllerName:
 80         //     控制器的名称
 81         //
 82         //   routeValues:
 83         //     路由的参数。
 84         //
 85         // 返回结果: 
 86         //     重定向结果对象。
 87         protected internal virtual RedirectToRouteResult RedirectToAction(string actionName, string controllerName, RouteValueDictionary routeValues);
 88         //
 89         // 摘要: 
 90         //     使用指定的操作名称,返回其 System.Web.Mvc.RedirectResult.Permanent 属性设置为 true 的 System.Web.Mvc.RedirectResult
 91         //     类实例。
 92         //
 93         // 参数: 
 94         //   actionName:
 95         //     操作名称。
 96         //
 97         // 返回结果: 
 98         //     使用指定的操作名称、控制器名称和路由值返回的 System.Web.Mvc.RedirectResult 类实例,其 System.Web.Mvc.RedirectResult.Permanent
 99         //     属性设置为 true。
100         protected internal RedirectToRouteResult RedirectToActionPermanent(string actionName);
101         //
102         // 摘要: 
103         //     使用指定的操作名称和路由值,返回其 System.Web.Mvc.RedirectResult.Permanent 属性设置为 true 的 System.Web.Mvc.RedirectResult
104         //     类实例。
105         //
106         // 参数: 
107         //   actionName:
108         //     操作名称。
109         //
110         //   routeValues:
111         //     路由值。
112         //
113         // 返回结果: 
114         //     使用指定的操作名称和路由值返回的 System.Web.Mvc.RedirectResult 类实例,其 System.Web.Mvc.RedirectResult.Permanent
115         //     属性设置为 true。
116         protected internal RedirectToRouteResult RedirectToActionPermanent(string actionName, object routeValues);
117         //
118         // 摘要: 
119         //     使用指定的操作名称和路由值,返回其 System.Web.Mvc.RedirectResult.Permanent 属性设置为 true 的 System.Web.Mvc.RedirectResult
120         //     类实例。
121         //
122         // 参数: 
123         //   actionName:
124         //     操作名称。
125         //
126         //   routeValues:
127         //     路由值。
128         //
129         // 返回结果: 
130         //     使用指定的操作名称和路由值返回的 System.Web.Mvc.RedirectResult 类实例,其 System.Web.Mvc.RedirectResult.Permanent
131         //     属性设置为 true。
132         protected internal RedirectToRouteResult RedirectToActionPermanent(string actionName, RouteValueDictionary routeValues);
133         //
134         // 摘要: 
135         //     使用指定的操作名称和控制器名称,返回其 System.Web.Mvc.RedirectResult.Permanent 属性设置为 true 的
136         //     System.Web.Mvc.RedirectResult 类实例。
137         //
138         // 参数: 
139         //   actionName:
140         //     操作名称。
141         //
142         //   controllerName:
143         //     控制器名称。
144         //
145         // 返回结果: 
146         //     使用指定的操作名称和控制器名称返回的 System.Web.Mvc.RedirectResult 类实例,其 System.Web.Mvc.RedirectResult.Permanent
147         //     属性设置为 true。
148         protected internal RedirectToRouteResult RedirectToActionPermanent(string actionName, string controllerName);
149         //
150         // 摘要: 
151         //     使用指定的操作名称、控制器名称和路由值,返回其 System.Web.Mvc.RedirectResult.Permanent 属性设置为 true
152         //     的 System.Web.Mvc.RedirectResult 类实例。
153         //
154         // 参数: 
155         //   actionName:
156         //     操作名称。
157         //
158         //   controllerName:
159         //     控制器名称。
160         //
161         //   routeValues:
162         //     路由值。
163         //
164         // 返回结果: 
165         //     一个 System.Web.Mvc.RedirectResult 类的实例,其 System.Web.Mvc.RedirectResult.Permanent
166         //     属性设置为 true。
167         protected internal RedirectToRouteResult RedirectToActionPermanent(string actionName, string controllerName, object routeValues);
168         //
169         // 摘要: 
170         //     使用指定的操作名称、控制器名称和路由值,返回其 System.Web.Mvc.RedirectResult.Permanent 属性设置为 true
171         //     的 System.Web.Mvc.RedirectResult 类实例。
172         //
173         // 参数: 
174         //   actionName:
175         //     操作名称。
176         //
177         //   controllerName:
178         //     控制器名称。
179         //
180         //   routeValues:
181         //     路由值。
182         //
183         // 返回结果: 
184         //     使用指定的操作名称、控制器名称和路由值返回的 System.Web.Mvc.RedirectResult 类实例,其 System.Web.Mvc.RedirectResult.Permanent
185         //     属性设置为 true。
186         protected internal virtual RedirectToRouteResult RedirectToActionPermanent(string actionName, string controllerName, RouteValueDictionary routeValues);
187         //
188         // 摘要: 
189         //     使用指定的路由值重定向到指定的路由。
190         //
191         // 参数: 
192         //   routeValues:
193         //     路由的参数。
194         //
195         // 返回结果: 
196         //     “重定向到路由”结果对象。
197         protected internal RedirectToRouteResult RedirectToRoute(object routeValues);
198         //
199         // 摘要: 
200         //     使用路由字典重定向到指定的路由。
201         //
202         // 参数: 
203         //   routeValues:
204         //     路由的参数。
205         //
206         // 返回结果: 
207         //     “重定向到路由”结果对象。
208         protected internal RedirectToRouteResult RedirectToRoute(RouteValueDictionary routeValues);
209         //
210         // 摘要: 
211         //     使用路由名称重定向到指定的路由。
212         //
213         // 参数: 
214         //   routeName:
215         //     路由的名称
216         //
217         // 返回结果: 
218         //     “重定向到路由”结果对象。
219         protected internal RedirectToRouteResult RedirectToRoute(string routeName);
220         //
221         // 摘要: 
222         //     使用路由名称和路由值重定向到指定的路由。
223         //
224         // 参数: 
225         //   routeName:
226         //     路由的名称
227         //
228         //   routeValues:
229         //     路由的参数。
230         //
231         // 返回结果: 
232         //     “重定向到路由”结果对象。
233         protected internal RedirectToRouteResult RedirectToRoute(string routeName, object routeValues);
234         //
235         // 摘要: 
236         //     使用路由名称和路由字典重定向到指定的路由。
237         //
238         // 参数: 
239         //   routeName:
240         //     路由的名称
241         //
242         //   routeValues:
243         //     路由的参数。
244         //
245         // 返回结果: 
246         //     “重定向到路由”结果对象。
247         protected internal virtual RedirectToRouteResult RedirectToRoute(string routeName, RouteValueDictionary routeValues);
248         //
249         // 摘要: 
250         //     使用指定的路由值,返回其 System.Web.Mvc.RedirectResult.Permanent 属性设置为 true 的 System.Web.Mvc.RedirectResult
251         //     类实例。
252         //
253         // 参数: 
254         //   routeValues:
255         //     路由名称。
256         //
257         // 返回结果: 
258         //     返回 System.Web.Mvc.RedirectResult 类的实例,其 System.Web.Mvc.RedirectResult.Permanent
259         //     属性设置为 true。
260         protected internal RedirectToRouteResult RedirectToRoutePermanent(object routeValues);
261         //
262         // 摘要: 
263         //     使用指定的路由值,返回其 System.Web.Mvc.RedirectResult.Permanent 属性设置为 true 的 System.Web.Mvc.RedirectResult
264         //     类实例。
265         //
266         // 参数: 
267         //   routeValues:
268         //     路由值。
269         //
270         // 返回结果: 
271         //     使用指定的路由值返回的 System.Web.Mvc.RedirectResult 类实例,其 System.Web.Mvc.RedirectResult.Permanent
272         //     属性设置为 true。
273         protected internal RedirectToRouteResult RedirectToRoutePermanent(RouteValueDictionary routeValues);
274         //
275         // 摘要: 
276         //     使用指定的路由名称,返回其 System.Web.Mvc.RedirectResult.Permanent 属性设置为 true 的 System.Web.Mvc.RedirectResult
277         //     类实例。
278         //
279         // 参数: 
280         //   routeName:
281         //     路由名称。
282         //
283         // 返回结果: 
284         //     使用指定的路由名称,返回其 System.Web.Mvc.RedirectResult.Permanent 属性设置为 true 的 System.Web.Mvc.RedirectResult
285         //     类实例。
286         protected internal RedirectToRouteResult RedirectToRoutePermanent(string routeName);
287         //
288         // 摘要: 
289         //     使用指定的路由名称和路由值,返回其 System.Web.Mvc.RedirectResult.Permanent 属性设置为 true 的 System.Web.Mvc.RedirectResult
290         //     类实例。
291         //
292         // 参数: 
293         //   routeName:
294         //     路由名称。
295         //
296         //   routeValues:
297         //     路由值。
298         //
299         // 返回结果: 
300         //     一个 System.Web.Mvc.RedirectResult 类的实例,其 System.Web.Mvc.RedirectResult.Permanent
301         //     属性设置为 true。
302         protected internal RedirectToRouteResult RedirectToRoutePermanent(string routeName, object routeValues);
303         //
304         // 摘要: 
305         //     使用指定的路由名称和路由值,返回其 System.Web.Mvc.RedirectResult.Permanent 属性设置为 true 的 System.Web.Mvc.RedirectResult
306         //     类实例。
307         //
308         // 参数: 
309         //   routeName:
310         //     路由名称。
311         //
312         //   routeValues:
313         //     路由值。
314         //
315         // 返回结果: 
316         //     使用指定的路由名称和路由值返回的 System.Web.Mvc.RedirectResult 类实例,其 System.Web.Mvc.RedirectResult.Permanent
317         //     属性设置为 true。
318         protected internal virtual RedirectToRouteResult RedirectToRoutePermanent(string routeName, RouteValueDictionary routeValues);
319         //
320         // 摘要: 
321         //     使用来自控制器的当前值提供程序的值更新指定的模型实例。
322         //
323         // 参数: 
324         //   model:
325         //     要更新的模型实例。
326         //
327         // 类型参数: 
328         //   TModel:
329         //     模型对象的类型。
330         //
331         // 返回结果: 
332         //     如果更新已成功,则为 true;否则为 false。
333         //
334         // 异常: 
335         //   System.ArgumentNullException:
336         //     model 参数或 System.Web.Mvc.ControllerBase.ValueProvider 属性为 null。

 

MVC中的RedirectToRouteResult方法+MVC中一个Action转到另一个Action(一个页面转到另一个页面)需要值提示某值为空时解决方法

标签:ring   values   exce   direct   action   控制   value   cte   base   

原文地址:https://www.cnblogs.com/fei-yu9999/p/14323125.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!