Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 编写此标记的其他方法_Jquery_Asp.net Mvc - Fatal编程技术网

Jquery 编写此标记的其他方法

Jquery 编写此标记的其他方法,jquery,asp.net-mvc,Jquery,Asp.net Mvc,有没有其他方法来写上面的内容?唯一的区别在于是否根据条件显示 谢谢, rodchar这里有另一种方式,但我不确定我是否比原来的更喜欢它;) 也许还有一个更短的符号。尽管jrrnS示例会起作用,但您可能需要考虑把它放在一个扩展方法:中。 <%= Html.Results(isTrue) %> 在你图书馆的一个班级里: public static class MyHtmlExtensions public static string Results(this Html

有没有其他方法来写上面的内容?唯一的区别在于是否根据条件显示

谢谢,
rodchar

这里有另一种方式,但我不确定我是否比原来的更喜欢它;)



也许还有一个更短的符号。

尽管jrrnS示例会起作用,但您可能需要考虑把它放在一个扩展方法:

中。
<%= Html.Results(isTrue) %>

在你图书馆的一个班级里:

public static class MyHtmlExtensions

    public static string Results(this HtmlHelper helper, bool hidden)
    {
        return String.Format("<div id=""myResults"" {0}>",
                             hidden = ? "style=""display: none;""" : "");
    }
}
公共静态类MyHtmlex
公共静态字符串结果(此HtmlHelper帮助程序,布尔隐藏)
{
返回String.Format(“”,
隐藏=?“style=”显示:无;“”:“”);
}
}

由于您使用了样式,您可以将其从html正文中完全删除

<style type="text/css">
div#myResults { display: <$= isTrue ? "none" : "block" %>; }
</style>
...
<div id=myResults>

div#myResults{display:;}
...
<%= Html.Results(isTrue) %>
public static class MyHtmlExtensions

    public static string Results(this HtmlHelper helper, bool hidden)
    {
        return String.Format("<div id=""myResults"" {0}>",
                             hidden = ? "style=""display: none;""" : "");
    }
}
<style type="text/css">
div#myResults { display: <$= isTrue ? "none" : "block" %>; }
</style>
...
<div id=myResults>