Insert searchable DropDownList selected value into database in ASP.Net MVC

akhter
 
on Nov 11, 2021 11:10 PM
544 Views

As per your refer link below.

Searchable DropDownList in ASP.Net MVC

After Changed from

@Html.DropDownListFor(m => m.CodeItem, Model.ItemList)

 to

@Html.DropDownList("ddlitem", Model.ItemList)

it value is not inserting into database.

@model WebApplication9.Models.Bigbalprd
@{
    Layout = null;
}
<html>
<head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css" />
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#ddlitem").select2();
        });
    </script>
    <meta name="viewport" content="width=device-width" />
    <title></title>
</head>

<body>
    <h1>Insert Data Into Data using MVC EDO</h1>>
    <div>
        @using (Html.BeginForm("Index", "Bigbale", FormMethod.Post))
        {
        <table border="1" bgcolor="yellow" width="400px" height="250px">
            <tr>
                <td>Class</td>
                <td>@Html.DropDownListFor(m => m.CodeItem, Model.ItemList ,"ddlitem")
                    @*@Html.DropDownList("ddlitem", Model.ItemList)*@</td>
            </tr>

            <tr>
                <td>Class</td>
                <td>@Html.DropDownListFor(m => m.SecID, Model.SectionList)</td>
            </tr>

            <tr>
                <td>Category</td>
                <td>@Html.DropDownListFor(m => m.CID, Model.SectionList)</td>
            </tr>

            <tr>
                <td>Qty</td>
                <td>@Html.TextBoxFor(m => m.Bpqty)</td>
            </tr>
            <tr>
                <td>Qty</td>
                <td>@Html.TextBoxFor(m => m.Bweight)</td>
            </tr>

            <tr>
                <td><input class="submit" type="submit" /></td>
            </tr>
        </table>
        }
    </div>
    <b>@ViewBag.saveresult</b>
</body>
</html>

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Nov 12, 2021 07:02 PM
akhter says:
@Html.DropDownListFor(m => m.CodeItem, Model.ItemList ,"ddlitem")

Change with below.

@Html.DropDownListFor(m => m.CodeItem, Model.ItemList, new { @id="ddlitem" })