[RESOLVED] Convert viewmodel to string
Hi,
How do I convert a view model to a string? This is what I have tried but it still returning the error "Cannot implicitly convert type 'System.Web.Mvc.ViewResult' to 'string'".
asp Code:
public string Index()
{
//Create a list of genres
var genres = new List<string> { "Rock", "Jazz", "Country", "Pop", "Disco" };
//Create the view model
var viewModel = new StoreIndexViewModel
{
NumberOfGenres = genres.Count(), Genres = genres
};
return View(viewModel.ToString());
}
Thanks,
Nightwalker
Re: Convert viewmodel to string
Never mind! I realized my mistake. I deleted the ActionResult that was created when the class was created. The above is suppose to look like this code:
asp Code:
public ActionResult Index()
{
//Create a list of genres
var genres = new List<string> { "Rock", "Jazz", "Country", "Pop", "Disco" };
//Create the view model
var viewModel = new StoreIndexViewModel
{
NumberOfGenres = genres.Count(),
Genres = genres
};
return View(viewModel);
}
Re: [RESOLVED] Convert viewmodel to string
Hey,
Looks to me like you are doing ASP.Net MVC, rather than straight up ASP.Net, so I am going to move this thread to the MVC thread, which is where questions on ASP.Net MVC should be asked.
Gary