gpt4 book ai didi

asp.net-mvc - 字符串中的 Razor 变量无法正确呈现

转载 作者:行者123 更新时间:2023-12-02 22:31:19 25 4
gpt4 key购买 nike

@using (Html.BeginForm())
{
int controlWidth=250;
@Html.TextBoxFor(m => m.studentFirstName, new { style = "width:@(controlWidth)px;" })

此代码呈现为

            <input data-val="true" data-val-required="The Student First Name field is required." id="studentFirstName" name="studentFirstName" style="width:@(controlWidth)px;" type="text" value="" />

可以理解,我希望它呈现为

            <input data-val="true" data-val-required="The Student First Name field is required." id="studentFirstName" name="studentFirstName" style="width:250px;" type="text" value="" />

我看过类似 ASP.NET MVC Razor Concatenation 的帖子这表明这种方法是正确的。知道我做错了什么吗?

最佳答案

我认为你做不到。内联模板只能在 HTML 内部使用,如 <li style="@(controlWidth)">或者如果您的方法支持内联模板。参见 http://vibrantcode.com/blog/2010/8/2/inside-razor-part-3-templates.html/关于如何编写支持内联模板的方法。

关于asp.net-mvc - 字符串中的 Razor 变量无法正确呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12203087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com