Equivalent of End / Response.End in razor?
Asked Answered
P

2

6

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?

Pinchbeck answered 24/2, 2011 at 22:37 Comment(1)
@ doesn't mean print! it starts a code block as your block starts with @if, you can't start a nested blockBadr
H
14

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();
Hyden answered 24/2, 2011 at 22:46 Comment(3)
Thanks for your answer - I'm not sure how to integrate it into the code though (apologies - beginner here) @if(count + count2 == 2){<text>Hello World</text> @Response.End();} - that still throws the CS1502 compilation errorPinchbeck
@Tom: @ means print. You don't want @.Hyden
FYI, return; worked great for me but Response.End() was what I tried before finding this post. It did end the request but did not output what was in the buffer.Seriema
H
0
@if (@Model.Container == null)
{
    <span style="font-weight: bold; ">Container Not Found </span style="font-weight: bold; ">
    return;
}
Heiskell answered 13/9, 2022 at 20:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.