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"); }     

ref: mvc3 page - ispostback functionality


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -