Search code examples
asp.net-mvcvisual-studio-2012

MVC list not working in Visual Studio 2012


Is there any additional configuration needed to get an MVC site working in visual studio 2012? My very basic site doesn't display the model.

Controller:

public class ISPLinkController : Controller
{
    // GET: /ISPLink/Details/5

    public Models.test Details(int id)
    {
        return new Models.test { url = "www.google.com", productGroup = "blah", name = "blah" };
    }
}

Model:

public class test
{
    public string name { get; set; }
    public string url { get; set; }
    public string productGroup { get; set; }
}

View:

@model StopAtNothingAdmin.Models.test

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>

<fieldset>
    <legend>test</legend>

    <div class="display-label">
     @Html.DisplayNameFor(model => model.name)
   ....Snip

GET on http://localhost:57608/ISPLink/Details/5

StopAtNothingAdmin.Models.test

(that is view source). There is nothing else


Solution

  • You need to return a View from your action:

    Assuming that your view is named Details.cstml

    public ActionResult Details(int id)
    {
        var model = new Models.test 
        { 
            url = "www.google.com", 
            productGroup = "blah", 
            name = "blah" 
        };
        return View(model);
    }
    

    There are plenty of good introductory tutorials on the asp.net site.