Friday, 24 February 2017

Default Checked Radio Button (@Html.RadioButtonFor, @Html.RadioButton) In MVC

2/24/2017 - By Pranav Singh 0

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.

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>

Please check the above code. In this one radio button control is having value 1, and we have bind the radiobutton to CustomerType control. So on the bases of the value radiobutton will be seleted or not. Now we have done run the application to check the output.



About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top