J.Gold J.Gold - 1 month ago 7
HTML Question

c# and HTML. What is this web application doing?

So I have a project for web, we are using Visual studios with a Web Application using ASP.NET with Razor. I have a piece of code (HTML and C#) with regards to the c# seen below I wish to know what that code is doing and if the right variables are in place from the code below.

@{
List<SelectListItem> rStatus = new List<SelectListItem>();
rStatus.Add(new SelectListItem
{
Text = "Never Married",
Value = "NeverMarried"
});
rStatus.Add(new SelectListItem
{
Text = "Widowed",
Value = "Widowed",
});
rStatus.Add(new SelectListItem
{
Text = "Divorce",
Value = "Divorce"
});
rStatus.Add(new SelectListItem
{
Text = "Seperated",
Value = "Seperated"
});


HTML

Please enter your current relationshop status: <br />
<select id="rStatus">
<option value="Never Married">Never Married</option>
<option value="Widowed">Widowed</option>
<option value="Divorce">Divorce</option>
<option value="Seperated">Seperated </option>
</select><br/>

Answer

The best way to know what your code is doing is by running it and taking a look at the output yourself. Also, your current razor code is useless since you are not using the SelectList. You manually created the <select></select> element instead of utilizing the @Html.DropdownList helper.

Try:

@{
    List<SelectListItem> rStatus = new List<SelectListItem>();
    rStatus.Add(new SelectListItem
    {
        Text = "Never Married",
        Value = "NeverMarried"
    });
    rStatus.Add(new SelectListItem
    {
        Text = "Widowed",
        Value = "Widowed",
    });
    rStatus.Add(new SelectListItem
    {
        Text = "Divorce",
        Value = "Divorce"
    });
    rStatus.Add(new SelectListItem
    {
        Text = "Seperated",
        Value = "Seperated"
    });
}

//Html.BeginForm
Please enter your current relationshop status: <br />
@Html.DropDownList("rStatus", rStatus)
.
.
//<input type="submit" value="Submit">

Since it is your project and you made the code, you better ask yourself or your team for information regarding on what you guys did. You can't be programming without having any idea of what you're doing.