You must Sign In to post a response.
  • Category: ASP.Net MVC

    Help To Bind List Box in MVC

    Controller :
    --------------

    [HttpPost]
    public async Task<ActionResult> GetTPAList()
    {

    var PrePayService = await this.prepayService.GetPrePayClientList();
    var jsonResult = this.Json(PrePayService, JsonRequestBehavior.AllowGet);
    jsonResult.MaxJsonLength = int.MaxValue;
    return jsonResult;
    }



    View :
    --------


    <div class="form-group">
    <label class="control-label col-xs-2">TPA</label>
    <div class="col-xs-3">

    @Html.DropDownList("TPAType", new List<SelectListItem>
    { new SelectListItem { Text = "TPA1", Value = "1", Selected=true},
    new SelectListItem { Text = "TPA2", Value = "2"},

    }, "Select Claim")





    </div>
    </div>

    Please any help to Bind items in that ListBox
  • #758951
    Follow the below steps to bind listbox in MVC
    - Create a new asp.net mvc application
    - Add Model file in it and add following code in it
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;

    namespace TestMVC.Models
    {
    public class CountryModel
    {
    public SelectList CountryListModel { get; set; }
    }
    }
    After creating model we will create the entity model finally we will create controller. After creating controller we will create action view.
    for more detail see below link
    http://www.aspdotnet-pools.com/2014/06/bind-and-retrieve-listbox-selected.html

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #758952
    Hi,

    but i want to implement my method..

    public async Task<ActionResult> GetTPAList()
    {

    var PrePayService = await this.prepayService.GetPrePayClientList();
    var jsonResult = this.Json(PrePayService, JsonRequestBehavior.AllowGet);
    jsonResult.MaxJsonLength = int.MaxValue;
    return jsonResult;
    }

    can u help it..

  • #758957
    controller :

    -----------------

    public async Task<ActionResult> GetTPAList()
    {

    var PrePayService = await this.prepayService.GetPrePayClientList();
    var jsonResult = this.Json(PrePayService, JsonRequestBehavior.AllowGet);
    jsonResult.MaxJsonLength = int.MaxValue;
    return jsonResult;
    }

    how to call those values in View ?

    any one help ..

  • #758960
    Hello Sriram,

    Refer the below example :

    @Html.DropDownList("Mobiledropdown3", new List<SelectListItem>
    { new SelectListItem { Text = "HTC DESIRE", Value = "1", Selected=true},
    new SelectListItem { Text = "Moto G", Value = "2"},
    new SelectListItem { Text = "GO mobiles", Value = "3"}
    }, "Select Mobile")

    Hope this will help you.
    Mark the answer if it helped you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #758961
    Hi Niran,

    i tried already but not getting result i need to bind values controller to View

    controller:

    public async Task<ActionResult> GetTPAList()
    {

    var PrePayService = await this.prepayService.GetPrePayClientList();
    var jsonResult = this.Json(PrePayService, JsonRequestBehavior.AllowGet);
    jsonResult.MaxJsonLength = int.MaxValue;
    return jsonResult;
    }

    any one help pls.

  • #760305
    Hi
    try this code for bind ddl in mvc5

    controller

    [HttpGet]
    public ActionResult LoginVal()
    {
    var list = new SelectList(new[]
    {
    new {ID="1",Name="name1"},
    new{ID="2",Name="name2"},
    new{ID="3",Name="name3"},
    },
    "ID", "Name", 1);
    ViewData["list"] = list;
    return View();
    }


    View code this

    @Html.DropDownList("list", ViewData["list"] as SelectList)


    you can go through following link for ddl bind mvc
    http://www.c-sharpcorner.com/UploadFile/4b0136/working-with-dropdownlist-in-mvc-5/

    http://stackoverflow.com/questions/25912719/mvc-5-dropdown-list-for-selecting-an-item

    http://stackoverflow.com/questions/867117/how-to-add-static-list-of-items-in-mvc-html-dropdownlist
    http://www.itorian.com/2013/04/populate-selected-item-in-dropdownlist.html

    http://www.codeproject.com/Questions/745499/ASP-NET-MVC-Problem-with-DropDownListFor

    Hope it will be helpful to you

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


  • Sign In to post your comments