tags:

views:

41

answers:

1

MVC use action attributes to map the same view for http get or post:

public ActionResult Index()
{
     return View();
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(int id)
{
 MyViewModel vm = new MyViewModel(id);
 return View();
}

Question is: in javascript, how can I know if the view is for http get command or http post command?

+1  A: 

Write a little bit of javascript on the page to indicate whether the request generating the view was a get or post.

<script type="text/javascript">
   var requestMethod = '<%= ViewContext.HttpContext.Request.HttpMethod %>';
</script>
tvanfosson