MVC Html Helper Rendering
I was wondering if it's possible to render an Html Helper in a View inside a codeblock. So instead of:
<% = Html.TextBox("sometextbox", "somethingelse") %>
I want to do:
<%
switch(SomeParameter)
{
case "blah":
Html.TextBox("sometextbox", "somethingelse")
break;
}
%>
And hav开发者_开发知识库e this render. Of course as it is, it wont render, so is there a way to programically decide if a textbox can be added without having to have a million delimiters in the page to accomplish this?
Thanks in advance!
<%
switch(SomeParameter)
{
case "blah":
%><%=Html.TextBox("sometextbox", "somethingelse")%><%
break;
}
%>
<%= %>
is just a shorthand notation for Response.Write()
though so the following should work too.
<%
switch(SomeParameter)
{
case "blah":
Response.Write(Html.TextBox("sometextbox", "somethingelse"));
break;
}
%>
All the HtmlHelpers return a string and don't output to the response stream directly by design.
Is this what your looking for?
<% switch (SomeParameter)
{
case "blah": %>
<%= Html.TextBox("sometextbox", "somethingelse") %>
<% break;
} %>
精彩评论