【问题标题】:How to set default checked radio button in nopcommerce 4.3如何在 nopcommerce 4.3 中设置默认选中单选按钮
【发布时间】:2020-10-30 10:23:40
【问题描述】:

我想在 nopcommerce 4.3 中默认检查三个选项中的一个单选按钮

这是我的代码,

<div class="col-md-6">
    <div class="raw">
        <div class="col-md-2">
            <div class="radio">
                <label>
                    @Html.RadioButton("LabourChargeUnit", "false", (Model.LabourChargeUnit == "PCS"), new { id = "LabourChargeUnit_PCS"})
                    @T("Admin.Catalog.Product.Fields.LabourChargeUnit.PCS")
                </label>
            </div>
        </div>
        <div class="col-md-2">
            <div class="radio">
                <label>
                    @Html.RadioButton("LabourChargeUnit", "false", (Model.LabourChargeUnit == "PER"), new { id = "LabourChargeUnit_PER" })
                    @T("Admin.Catalog.Product.Fields.LabourChargeUnit.PER")
                </label>
            </div>
        </div>
        <div class="col-md-2">
            <div class="radio">
                <label>
                    @Html.RadioButton("LabourChargeUnit", "true", (Model.LabourChargeUnit == "GM"), new { id = "LabourChargeUnit_GM" })
                    @T("Admin.Catalog.Product.Fields.LabourChargeUnit.GM")
                </label>
            </div>
        </div>
    </div>
</div>

现在,我尝试了很多方法,例如 new{@checked = "checked"}, true/false, 0/1,但没有奏效。

【问题讨论】:

    标签: html asp.net-mvc radio-button nopcommerce checked


    【解决方案1】:

    nopCommerce4.3 源码中有很多例子。您可以查看 Presentation==>Nop.Web==>Views==>Customer==>Register.cshtml 并查看以下代码

    <div class="gender">
        <p class="mb-1 d-inline-block">
           <input type="radio" asp-for="Gender" value="M" checked="@(Model.Gender == "M")" id="gender-male" />
           <label class="forcheckbox mr-1 d-block text-left" for="gender-male">
                <span class="">  @T("Account.Fields.Gender.Male") </span>
            </label>
          </p>
          <p class="mb-1 d-inline-block">
              <input type="radio" asp-for="Gender" value="F" checked="@(Model.Gender == "F")" id="gender-female" />
                 <label class="gender-female text-left" for="gender-female">
                    <span class=""> @T("Account.Fields.Gender.Female") </span>
                </label>
          </p>
    </div>
    

    【讨论】:

      【解决方案2】:
      @T("帐户.字段.性别.男性") @T("账户.字段.性别.女性")

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 2021-01-06
      • 1970-01-01
      • 2015-12-10
      • 1970-01-01
      • 2023-03-04
      • 2021-11-05
      • 2018-06-26
      • 2021-02-18
      • 2016-11-28
      相关资源
      最近更新 更多