Abhishek Shrivastava

Abhishek Shrivastava

  • 1.5k
  • 133
  • 6.8k

How display two columns in Mvc WebGrid with single object

May 25 2017 8:36 AM
I am new to MVC and I want to display name of a user in two columns in a WebGrid as display below.
 
 
User 1   User 2
     
     
User 3   User 4
 
Currently the web grid display data in below format.
 
User 1
User 2
User 3
User 4
 
I am binding my WebGrid with List<string>, list contains username.
 
My Controller
public ActionResult Index()
{
List<string> userList = new List<string>();
userList.Add("User1");
userList.Add("User2");
userList.Add("User3");
userList.Add("User4");
return View(userList);
}
 
My Cshtml
 
enter code here
@using (Html.BeginForm())
{
var grid = new WebGrid(Model);
@grid.GetHtml(columns: grid.Columns(grid.Column(format: (item) => item)));
}

Answers (2)