This
article will show you how you can make a default checked radio button in mvc.
In this I have used model to set the default checkbox in radiobuttonfor control.
So for this article first we will create a model class.
So for this article first we will create a model class.
public class CustomerLogin
{
public string LoginId { get; set; }
public string Password { get; set; }
public int CustomerType { get; set; }
}
|
Here we
will use the Customer property to make the radiobutton checked default. Now
first we will create the controller class and add the below code.
[HttpGet]
public ActionResult
Index()
{
CustomerLogin
_customerLogin = new CustomerLogin();
_customerLogin.CustomerType = 1;
return
View(_customerLogin);
}
|
Here we
have assign the value to the CustomerType. Now we will create the view and add
the below code into the page.
@model ConnectSeekers.Models.CustomerLogin
<table width="100%" border="0">
<tr>
<td>
@Html.RadioButtonFor(m => m.CustomerType, "1", new { @class = "radio"
})Buyer
</td>
<td>
@Html.RadioButtonFor(m =>
m.CustomerType, "2", new { @class = "radio" })Seller
</td>
</tr>
</table>
|
0 comments:
Please let me know your view