locked
How to get selected value from drop downlist asp.net mvc view?? Please find the below code RRS feed

  • Question

  • User591932912 posted
    @model IEnumerable<FamilyTreeMvc.Models.FAMILY>
    
    @{
        ViewBag.Title = "Index";
    }
    
    <h2>Index</h2>
    
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
    <h3>Select Person</h3>
    
    <h3>  @Html.DropDownList("PERSONID", null, htmlAttributes: new { @class = "form-control" })</h3>
    <table class="table">
        <tr>
            <th>
    
                @Html.DisplayNameFor(model => model.PERSONID)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.PERSON.IMAGE)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.FAMILYRELATION.RELATIONDESC)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.PERSON.FIRSTNAME)
            </th>
            <th></th>
        </tr>
    
        @foreach (var item in Model)
        {
    
    
            if (@item.PERSONID ==6)//Instead of static value i want to get selected value from the dropdown list
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.PERSONID)
                    </td>
                    <td>
                        <img src="@Url.Content("~/Images/" + (@item.PERSON.IMAGE))" style="height:100px;width:100px" />
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.FAMILYRELATION.RELATIONDESC)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.PERSON.FIRSTNAME)
                    </td>
                    <td>
                        @Html.ActionLink("Edit", "Edit", new { id = item.RID }) |
                        @Html.ActionLink("Details", "Details", new { id = item.RID }) |
                        @Html.ActionLink("Delete", "Delete", new { id = item.RID })
                    </td>
                </tr>
    
            }
    
    
    
        }
    </table>
    


    @model IEnumerable @{ ViewBag.Title = "Index"; }

    Index

    @Html.ActionLink("Create New", "Create")

    Select Person

    @Html.DropDownList("PERSONID", null, htmlAttributes: new { @class = "form-control" })

    @foreach (var item in Model) { if (@item.PERSONID ==6) //Here I want to get drop downlist selected value instead of giving static value {} }

    @Html.DisplayNameFor(model => model.PERSONID) @Html.DisplayNameFor(model => model.PERSON.IMAGE) @Html.DisplayNameFor(model => model.FAMILYRELATION.RELATIONDESC) @Html.DisplayNameFor(model => model.PERSON.FIRSTNAME)
    @Html.DisplayFor(modelItem => item.PERSONID) @Html.DisplayFor(modelItem => item.FAMILYRELATION.RELATIONDESC) @Html.DisplayFor(modelItem => item.PERSON.FIRSTNAME) @Html.ActionLink("Edit", "Edit", new { id = item.RID }) | @Html.ActionLink("Details", "Details", new { id = item.RID }) | @Html.ActionLink("Delete", "Delete", new { id = item.RID })

    Monday, April 26, 2021 8:44 AM

All replies

  • User475983607 posted

    See your other thread with the same subject.  

    https://forums.asp.net/p/2175872/6337208.aspx?Asp+net+MVC

    The selected value is passed from the Action to the View.   Either this value comes for state like a database or user selection and an HTTP POST.  Can you explain how your application works and share the relevant code?

    Monday, April 26, 2021 10:08 AM