Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

c# - Problem displaying a webgrid in MVC ASP NET

I need populate two DropDownList's from values obtained from a database table using MySql database and view model using ASP NET MVC.

After populate a DropDownList's I need filter WebGrid using the value selected on single DropDownList.

With this controller part

public ActionResult RecoveryAll()
{
    PersonModel model = new PersonModel();
    model.Dates_List = PopulateDates(null); //First DDL
    model.Ticket_List = PopulateTkt(null);  //Second DDL
    return View(model);
}

[HttpPost]
public ActionResult RecoveryAll(string country)
{
    PersonModel model = PopulateModel(country);
    return View(model);
}

private static PersonModel PopulateModel(string country)
{
    PersonModel model = new PersonModel();
    return model;
}

on return I have

enter image description here

Now I need displaying the WebGrid and edit the view to

@webGrid.GetHtml(
    htmlAttributes: new { @id = "WebGrid", @class = "Grid" },
    columns: webGrid.Columns(
             webGrid.Column("CustomerID", "Customer Id"),
             webGrid.Column("ContactName", "Customer Name"),
             webGrid.Column("City", "City"),
             webGrid.Column("Country", "Country")))

But how to do edit the controller for displaying WebGrid?

Because the debug on visual studio 2019 now I have this error

You must bind a data source to be able to do this

Help me to do it.

question from:https://stackoverflow.com/questions/65921928/problem-displaying-a-webgrid-in-mvc-asp-net

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...