1

是否需要任何其他配置才能使 MVC 站点在 Visual Studio 2012 中工作?我有一个非常基本的网站设置,但它不工作。它表示错误,但表示模型。

控制器

    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" };
        }
}

模型

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

看法

@model StopAtNothingAdmin.Models.test

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>

<fieldset>
    <legend>test</legend>

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

进行http://localhost:57608/ISPLink/Details/5

StopAtNothingAdmin.Models.test

(即查看源代码)。没有别的了

4

1 回答 1

3

您需要从您的操作中返回一个视图

假设您的视图已命名Details.cstml

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

aps.net mvc站点上有很多很好的介绍性教程。

于 2012-08-22T07:15:30.083 回答