English 中文(简体)
发现错误后, 我如何退出一组代码?
原标题:How do i exit a block of code after error detection
  • 时间:2012-05-25 10:13:53
  •  标签:
  • c#-4.0
  • razor

In VB/VB.NET, exiting a block of code anytime and anywhere in the code block is handled using EXIT SUB/EXIT FUNCTION/EXIT LOOP e.t.c. I expected RETURN FALSE should work in razor/c# but its not in a function nor sub-routine.its just @{ }.This gets me confused.please, whats the trick or criteria behind this? for example

@{
if(Websecurity.isAuthenticated){
   //do something
}else{
   json.Write("<li>You must be authenticated</li>", writer);
   return false; //this is my line of question
}
   //remaining code block
}

第6行是我从剩下的代码块中退出的问题线,就像 VB.NET 或 VB 中的 EXIT Sub 一样。

最佳回答

请尝试 return; , 应该有效 。

问题回答

暂无回答




相关问题
How to update shared view adminheader.cshtml from a model

I ve added a drop down into my shared adminheader.cshtl view and it needs to be dynamically updated from data from a table. So when I use another view like routeplan.cshtml I load the view from ...

ASP.NET MVC Razor view engine

After reading Scott Guthrie s blog entry about the new Razor view engine for ASP.NET MVC and reading this question comparing the available view engines. Razor seems to address most of the problems ...

Client Id for Property (ASP.Net MVC)

I m trying to do a label for a TextBox in my View and I d like to know, how can I take a Id that will be render in client to generate scripts... for example: <label for="<%=x.Name.ClientId%>"...

Get Current Area Name in View or Controller

How do you get the current area name in the view or controller? Is there anything like ViewContext.RouteData.Values["controller"] for areas?

MVC which submit button has been pressed

I have two buttons on my MVC form: <input name="submit" type="submit" id="submit" value="Save" /> <input name="process" type="submit" id="process" value="Process" /> From my Controller ...

热门标签