Many times after the deletion of an element, we all want to return to the original page, how to achieve it.
Suppose in the index.cshtml (or aspx) of Xcontroller:
<a>
Delete </a>, in order for the deletion to return to the index page, you can use:
<a>
And in the XController.cs, the original
[HttpPost]
ActionResult Delete (int id)
{
try
{
...
Return Redirecttoaction (...);
}
Catch
{
}
}
To
[HttpPost]
ActionResult Delete (int id, string backurl)
{
try
{
...
) Return Redirect (Backurl);
}
Catch
{
}
}
Request.url contains all the address information (including parameters), which is a URI type instead of string, so many additional operations can be performed (such as as long as address/server/query parameters, etc.), and the details can be searched online.
Never tried "/area/controller/action/id" how to do, should be roughly similar.
2011-08-18 added: When there is a "&" in the Backurl (where there are multiple parameters to return), this will be a direct error , you must:
<a>
In order to encode the return code (all of the special characters into% or whatever, Chinese also run).
If you write more, you'll find trouble as a helper:
public static partial class Helper
{public
static string Returnurlof (this HtmlHelper htmlhelper, Httprequestbase request)
{return
httputility.urlencode (request). Url.tostring ());
}
Write the Html.returnurlof (request) in the place where you originally wanted to write those things (request is a property of view and is available as HTML).
But not the laziest is only more lazy, if you and I have the same <a> encapsulation, then the interface can be encapsulated directly into:
@Html. Link ("x", "/sfc/categories/delete?rootid=" + root.id + "&id=" + model.id, Returnrequest:request)
All encode and request issues are handled inside link, which is the ultimate practice.
Download the Free Agile Development textbook: "The Martian Agile Development Handbook"