MVC3页面 - 的IsPostBack一样的功能 [英] MVC3 Page - IsPostback like functionality
问题描述
我把从_Layout.cshtml观点相同的控制器多次。因此,在此控制器,我怎么能在运行时发现如果它仍然被渲染,或者一个全新的页面请求正在取得相同的网页?
I call the same controller many times from _Layout.cshtml view. So in this controller, how can I discover at runtime if it's still same page that is rendering or if a brand new page request is being made?
在asp.net可以使用的IsPostBack摸不着头脑。你怎么能判断一个全新的请求一个页面中MVC3内容?
In asp.net you can use ispostback to figure this out. How can you tell if a brand new request is being made for a page in MVC3?
感谢
推荐答案
有没有这样的想起MVC。你已经可以处理信息操作,获取或两者兼而有之。您可以过滤了每个动作可以用手柄 [HttpPost]
和 [HTTPGET]
属性。
There's no such think on MVC. You've actions that can handle POSTs, GETs or both. You can filter what each action can handle using [HttpPost]
and [HttpGet]
attributes.
在MVC中,你可以得到的IsPostBack
最接近的是这样的你的行动中:
On MVC, the closest you can get to IsPostBack
is something like this within your action:
public ActionResult Index()
{
if (Request.HttpMethod == "POST")
{
// Do something
}
return View();
}
因此,
[HttpPost]
public ActionResult Create(CreateModel model)
{
if (Request.HttpMethod == "POST") // <-- always true
{
// Do something
}
return RedirectToAction("Index");
}
这篇关于MVC3页面 - 的IsPostBack一样的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!