user3623300 user3623300 - 1 year ago 64
C# Question

Values in View and split a string

First off, I use this to get some kind of data from the database

string Query = "SELECT * FROM dbo.Person WHERE PersonId != @ID";
SqlParameter Parameter = new SqlParameter("@ID", ID);
IEnumerable<???> = db.Person.SqlQuery(Query, Parameter).ToList();

What should I return my result as a list of?

Then I just pass it along into my View right?

return View(???);

Should I edit my data before sending it to the view, or should I edit it in the View?

Because one of my values in the database is a value separated by semicolons


So I want to separate them, but how can I separate them, and if I separate in my controller, then how do I pass multiple values to the View?

Answer Source

The result can be anything as long as the type your return in the controller, is also implemented as Model in the View. The View receives this type. So return View(IEnumerable<Person>) should be fine.

I would suggest you edit the data in the model, but technically it doesn't matter. You can edit your data while looping through it in the view.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download