Search code examples
asp.netrazorwebmatrix

Equivalent of End / Response.End in razor?


I'm trying to stop the rest of a page loading based on some parameters; but am not sure of the correct syntax.

@if(dayRes + dayTri == 2){<text>Sorry, etc</text> @Response.End}

The above throws this error: CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments

Any ideas?


Solution

  • Your code tries to print Response.End to the page.

    You can just write (in your code block)

    return;
    

    to stop running the generated Execute() method.

    You can also call End as a method inside of your code block:

    Response.End();