asp.net mvc - How to detect postback in javascript? -
i need fill text current datetime on first page load using javascript. mean i'm looking analog page.ispostback property in asp.net, in js.
i've found solutions, adviced use server-side code detect postback , pass variable client-side. i'm using mvc, , there no property such page.ispostback...
please, me find answer
there's no such think on mvc. you've actions can handle posts, gets or both. can filter each action can handle using [httppost] , [httpget] attributes.
on mvc, closest can ispostback within action:
public actionresult index() { if (request.httpmethod == "post") { // } return view(); }
therefore,
[httppost] public actionresult create(createmodel model) { if (request.httpmethod == "post") // <-- true { // } return redirecttoaction("index"); }
Comments
Post a Comment