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&ReturnUrl=@Url.Encode(Request.RawUrl)" class="btn green"><i class="icon-plus"></i> 添加文章</a>
3.提交表单视图
<form>
<a href="/article/edit?menuId=BB00&id=@m.ID&ReturnUrl=@Url.Encode(Request.RawUrl)" title="编辑" class="btn blue">
...
@Html.Hidden("returnUrl", Request.QueryString["ReturnUrl"])
</form>
posted on 2015-05-25 08:43 CeleryCabbage 阅读(1675) 评论(1) 编辑 收藏 举报