how to get DropDownList view selected value in controller

3 posts, 0 answers
  1. Amitkumar
    Amitkumar avatar
    7 posts
    Member since:
    Mar 2014

    Posted 08 Apr 2014 Link to this post


    [HttpPost]
    public ActionResult Submit(HttpPostedFileBase files,)
    {
    if (files != null && files.ContentLength > 0)
    {
    var filename = Path.GetFileName(files.FileName);
    MemoryStream target = new MemoryStream();
    files.InputStream.CopyTo(target);
    byte[] data = target.ToArray();

    //"Reconcile" is from DropDown1(Cabinate) and  "Microsoft" is DropDown2(Publisher)

    CheckInDoc( "Reconcile", "Microsoft", filename , data);
     
    }
    return RedirectToAction("Result");
    }





    <form method="post" action='@Url.Action("Submit")' style="width:45%">
    <h3>Cabinate</h3>
    @(Html.Kendo().DropDownList()
    .Name("Cabinate")
    .DataTextField("Text")
    .DataValueField("Value")
    .Events(e => e.Change("change"))
    .BindTo(new List<SelectListItem>() {
    new SelectListItem() {
    Text = "Selet Cabinate",
    Value = "-1"
    },
    new SelectListItem() {
    Text = "Reconcile",
    Value = "1"
    },
    new SelectListItem() {
    Text = "Discovery",
    Value = "2"
    }
    })
    .Value("-1")
    )
    <h3>Folder</h3>
    @(Html.Kendo().DropDownList()
    .Name("Folder")
    .BindTo(new List<string>() { "Select Publisher", "Microsoft", "Telerik", "Redhate" })
    )
     
    <div class="demo-section">
    @(Html.Kendo().Upload()
    .Name("files")
    )
    <p>
    <input type="submit" value="Submit" class="k-button" />
    </p>
    </div>
    </form>
  2. Amitkumar
    Amitkumar avatar
    7 posts
    Member since:
    Mar 2014

    Posted 08 Apr 2014 Link to this post

    Anyways finally I used
    FormCollection to get the post data. Let me know if someone has better idea.
    I am newbie

    Thanks
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 09 Apr 2014 Link to this post

    Hello,

    Did you try to add a string Cabinate parameter to the Submit Action method. This will tell the MVC framework to map the posted values to the method's parameters. The other option is to retrieve the posted values manually using the FormCollection, like you've already done.

    Regards,
    Georgi Krustev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top