【问题标题】:how can I replace the html syntax to razor syntax如何将 html 语法替换为 razor 语法
【发布时间】:2014-03-25 20:10:13
【问题描述】:

我有一个 html 格式的页面,我想将其更改为 razor 语法。代码如下:

<label class="class1" for="textinput">
    <button class="class2" href="#abc">Send</button>&nbsp;To
</label>

【问题讨论】:

    标签: html razor html-helper


    【解决方案1】:

    只需使用 Razor HtmlHelpers

    @Html.LableFor(model => model.textinput)
    //or @Html.Lable("textinput")
    <button class="class2" <--!href="#abc"-->>Send</button>&nbsp;To
    //we don't have 'href' attribute in button tag
    @html.ActionLink("Action", "Controller", null/*routing values*/)
    

    你想在Label 里面有一个Button 吗?了解更多read this.

    编辑: According to W3,标签本身可能位于关联控件之前、之后或周围。请参阅Should I put input tag inside label tag?Should we put inside ? 以获得更多理解。但是,如果你真的想这样做,你不能使用@Html.Label@Html.LabelFor,因为不可能通过 Razor 语法将元素放入其中。

    【讨论】:

    • 嗨阿米尔,我只想要标签内的按钮
    • @Divya 我为你更新了答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-28
    • 2012-04-05
    • 2019-11-25
    • 2014-10-13
    • 1970-01-01
    相关资源
    最近更新 更多