'How to set default checked radio button in nopcommerce 4.3
I want to check bydefault one radiobutton from three option in nopcommerce 4.3
Here is my code,
<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>
Now, I have tried many things like new{@checked = "checked"}, true/false, 0/1 but didnt work.
Solution 1:[1]
There are lots of example in the nopCommerce4.3 source. You can take a look at Presentation==>Nop.Web==>Views==>Customer==>Register.cshtml and see the below code
<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>
Solution 2:[2]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | sina_Islam |
Solution 2 | user18027614 |