Asp.net MVC中ReturnUrl的使用

1.控制器(Controller)
[HttpPost]
[ValidateInput(false)]
public ActionResult Add(Article article,string returnUrl)
{
if (ModelState.IsValid)
{
string path = null;
if (SaveImg(out path))
{
article.PicUrl = path;
article.IsPicture = true;
}
db.Articles.AddObject(article);
db.SaveChanges();
return Redirect(returnUrl);
}
ViewBag.ArticleTypes = GetArticleTypeList().Where(p => p.ID != 0);
return View(article);
}
2.列表视图
<a href="/article/add/?menuid=BB00&[email protected](Request.RawUrl)" class="btn green"><i class="icon-plus"></i>&nbsp;添加文章</a>
3.提交表单视图
<form>
<a href="/article/edit?menuId=BB00&[email protected]&[email protected](Request.RawUrl)" title="编辑" class="btn blue">
...
@Html.Hidden("returnUrl", Request.QueryString["ReturnUrl"])
</form>

你可能感兴趣的:(asp.net)