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

    How to pass Viewdata to View Grid

    LINQContext obj = new LINQContext();
    public void Dataresults()
    var result = from r in obj.tablename select r;
    ViewData["rslt']= result;


    How to pass this ViewData in MVC grid
  • #768087
    Hi Lily,

    You can directly pass this ViewData to the View file (CSHTML)

    @if(ViewData["rslt"] != null)

    foreach (System.Data.DataRow dr in (ViewData["rslt"] as System.Data.DataTable).Rows)

    // Condition as per your requirement




  • #768089
    you need to use 'WebGrid' in that you need to provide model name and column name to be display and you can achieve it, see below snippet

    @using (@Html.BeginForm("Index", "Home"))
    var grid = new WebGrid(Model.modelname1,canSort:false);
    grid.Column("column1", "Viewdatacolumn"),
    ), mode: WebGridPagerModes.Numeric)

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

Sign In to post your comments