I have a view in my asp.net mvc app, this view need a condition for display (or not) some information.

Unfortunately my condition need to get an object from the session and check several conditions

For example

<body>
<sometag>
<....>
<%
var oS = HttpContext.Current.Session["key"];

if(oS.some && oS.other == "other" && oS.Propertie == varInThisPage.Propertie && etc){

if(){

   if(){

       //in any place of universe
       return true;

       }
   }
return false; // for other
}
 %>
</body>

The problem is that I have that checks this condition in various part of the view, and do not want to create a method in the model, I feel that assassinate MVC

I thinking create a method in <% %> tag, but not working

bool MyMethod(){
var oS = HttpContext.Current.Session[InfoWeb.Models.SessionObjects.ConstSession.RT_SESSION];
....
return condition;    
}

In <% Visual Studio show error expected {

When i run, show error in next line with C# code

<%: Html.ActionLink("Create New", "BG", "CVSD")%> <!-- this work before i create method -->

I use asp.net-mvc 2

有帮助吗?

解决方案

<% %> blocks can only contain statements.
(the code in the block is placed inside the generated function)

To add fields or methods to the generated class, use <script runat="server">...</script>.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top