简体   繁体   English

MVC HTML Helper渲染

[英]MVC Html Helper Rendering

I was wondering if it's possible to render an Html Helper in a View inside a codeblock. 我想知道是否有可能在代码块内的视图中渲染HTML助手。 So instead of: 所以代替:

<% = Html.TextBox("sometextbox", "somethingelse") %>

I want to do: 我想要做:

<% 
switch(SomeParameter) 
{
   case "blah":
       Html.TextBox("sometextbox", "somethingelse")
   break;
}
%>

And have 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. 虽然<%= %>只是Response.Write()的简写形式,所以以下内容也应该起作用。

<% 
    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. 所有的HtmlHelpers返回一个字符串,并且不会按设计直接输出到响应流。

Is this what your looking for? 这是您要找的东西吗?

  <% switch (SomeParameter)
       {
           case "blah": %>
    <%= Html.TextBox("sometextbox", "somethingelse") %>
    <% break;
       } %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM