Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi Iam new to MVC . I had a view which have a dropdownlist filled with a viewbag.
Now I want to send the selected value to My action on Button Click. But it is always
giving Zero can anyone tell me where I am wrong

What I have tried:

Controller
<pre><pre>public class MastersActionController : Controller
    {
        private ArtEntities db = new ArtEntities();
      

        public ActionResult SignRequest()
        {
            var model = new List<RequestSignModel>();
            Models.RequestSignModel sgreqmodel = new Models.RequestSignModel();
            var q = from sampmstr in db.SampCutReqMasters
                    join
smpasg in db.SamCutAssignmentMasters on sampmstr.SampCutreqID equals smpasg.SampCutreqID
                    where smpasg.SignedBYMaster == false
                    select new { sampmstr.ReqNum, smpasg.CutAssignID };

            ViewBag.CutAssignID = new SelectList(q, "CutAssignID", "ReqNum");

            return View();
        }

        public ActionResult EditSignRequest(Models.RequestSignModel mdl)
        {
            int CutAssignID = mdl.CutAssignID;

            var q = from sampass in db.SamCutAssignmentMasters
                    where sampass.CutAssignID == CutAssignID
                    select sampass;

            foreach (var element in q)
            {
                element.SignedBYMaster = true;
                element.SignedDate = DateTime.Now;
            }

            db.SaveChanges();

            return View();
        }



        public ActionResult ShowHistory()
        {


            return View();
        }
    }



And My view Is


@model WebArtSampler.Models.RequestSignModel
@{
    ViewBag.Title = "SignRequest";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>SignRequest</h2>

@using (Html.BeginForm("EditSignRequest", "MastersAction"))
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">

        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.CutAssignID)

        <div class="form-group">
            @Html.LabelFor(model => model.CutAssignID, "Req#", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
           
         
                @*@Html.DropDownListFor(model => model.CutAssignID, (SelectList)ViewBag.CutAssignID, "--Select One--", htmlAttributes: new { @class = "form-control" })*@

                @Html.DropDownListFor(model => model.CutAssignID, (SelectList)ViewBag.CutAssignID, htmlAttributes: new { @class = "form-control" })
                                
                
            </div>
        </div>



        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
          <input id="btnSubmit" type="submit" value="Submit" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900