Reputation: 165
i'm trying to get started with MVC (using .net core). Here is the controller method:
[HttpGet]
public IActionResult Contacts()
{
//THIS RENDERS THE VIEW AS HTML
//return View(Mapper.Map<List<WebContacts.Business.Contact>, List<ContactsViewModel>>(WebContacts.Business.Contact.GetContacts().ToList()));
// THIS DISPLAYS THE RETURNED JSON Object
return Ok(Mapper.Map<List<WebContacts.Business.Contact>, List<ContactsViewModel>>(WebContacts.Business.Contact.GetContacts().ToList()));
}
In the controller if I return View(); it renders the razor partial view as expected (html etc), if i use
Return OK() i just get the JSON]1
Thanks for any help. ID
Upvotes: 1
Views: 140
Reputation: 560
return OK(object) sends a HTTP response to the client containing the object. return View(object) passes processing over to the view engine which returns HTML to the client. What problem are you trying to resolve?
Upvotes: 2