Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET 5 IsPost gone?

i cant see from the razor view if the Http request is a postback

in MVC 5 we had the IsPost

but it does not work by me on MVC 6

i cant even get the Request object in the view

like image 884
CMS Avatar asked Mar 15 '23 06:03

CMS


1 Answers

you could create a extension method on ViewContext to access ViewContext.HttpContext.Request and check for the Method. Possibly like this:

public static class ViewContextExtensions
{
    public static bool IsPost(this ViewContext viewContext)
    {
        return viewContext.HttpContext.Request.Method == "POST";
    }
}
like image 128
Juergen Gutsch Avatar answered Mar 25 '23 06:03

Juergen Gutsch