开发者

ASP.NET MVC go back to correct view

I have 开发者_开发百科Person controler with List Edit Create methods after edit of Person i go back to Person list

NOW I have other controler Family (Family - Person is one-to-many )

on Detail Family I have list of Persons with edit linked to Person/Edit/Id

When user clicks Save Person after editing I want to go back to Family Detail if he came from there or to Peron list if he Edited Person from Person list

Some help please

Thanks


You can use

HttpContext.Request.UrlReferrer

So to go back to the last view you would use something like:

Response.Redirect(HttpContext.Request.UrlReferrer.OriginalString);

Edit after comment:

Indeed you would get send back to the edit page in this case, what you could do if you don't want anyone to see querystrings is: (assuming you are using html.form to post the data).

On your Edit person page, inside of the form add something like:

 @using (Html.BeginForm(new { RedirectUrl = HttpContext.Current.Request.UrlReferrer.OriginalString } )

and then on the controller pick it up as:

 public Void Edit(int id, string RedirectUrl)
    {
       //save stuff
       return Redirect(RedirectUrl);
    }


You can pass the URL of the previous page in the query string for the edit page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜