问题
I'm using a single razor page (cshtml) that has a form
and @functions{}
section to capture an OnPost()
. All of that works fine.
In the HTML section, I need to know when a post back has occurred and display a message. I'm not sure where or how that is done in a Razor Page. I've tried IsPost
but that isn't available.
I created a string property in the class and set a value on it in OnPost
but once I'm in the view, the property is null
.
I assigned a value into ViewData["mystring"]
but it is also null once I get into the view.
-- EDIT --
It seems the issue is that I'm trying to set a property in OnPost, which is the request. After OnPost, OnGet will always fire. OnGet is the Response. I can see the flip from POST
to GET
in this.Request.Method
. So I lose any indication that a postback happened.
Any suggestions on how that is done?
回答1:
You should use use Post-Redirect-Get pattern. The message can be stored in TempData
来源:https://stackoverflow.com/questions/47820332/how-to-detect-postback-in-razor-page