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?

cavill
  • 590
  • 6
  • 19

2 Answers2

15

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();
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Thanks for your answer - I'm not sure how to integrate it into the code though (apologies - beginner here) `@if(count + count2 == 2){Hello World @Response.End();}` - that still throws the CS1502 compilation error – cavill Feb 24 '11 at 22:59
  • @Tom: @ means print. You don't want @. – SLaks Feb 24 '11 at 23:07
  • 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. – Ben Gripka Sep 29 '16 at 17:39
0
@if (@Model.Container == null)
{
    <span style="font-weight: bold; ">Container Not Found </span style="font-weight: bold; ">
    return;
}
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77