Results 1 to 3 of 3

Thread: [RESOLVED] Convert viewmodel to string

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [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:
    1. public string Index()
    2.         {
    3.             //Create a list of genres
    4.             var genres = new List<string> { "Rock", "Jazz", "Country", "Pop", "Disco" };
    5.  
    6.             //Create the view model
    7.             var viewModel = new StoreIndexViewModel
    8.             {
    9.                 NumberOfGenres = genres.Count(), Genres = genres
    10.             };
    11.             return View(viewModel.ToString());
    12.  
    13.         }

    Thanks,


    Nightwalker
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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:
    1. public ActionResult Index()
    2.         {
    3.             //Create a list of genres
    4.             var genres = new List<string> { "Rock", "Jazz", "Country", "Pop", "Disco" };
    5.  
    6.             //Create the view model
    7.             var viewModel = new StoreIndexViewModel
    8.             {
    9.                 NumberOfGenres = genres.Count(),
    10.                 Genres = genres
    11.             };
    12.             return View(viewModel);
    13.         }
    Last edited by Nightwalker83; Jun 19th, 2011 at 02:23 AM. Reason: Fixed spelling!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width