-2

我在使用 asp.net mvc 4 开始剑道网格时遇到了麻烦。我有控制器方法,它正在传递数据以查看效果很好,但我试图在剑道网格中查看。我通过 ManageNuGet 添加了参考。

这是我的代码

 public ActionResult createNewStore()
    {
        return View();
    }

    [HttpPost]
    public ActionResult createNewStore(Store storeModel)
    {
          var db = new AppContext();

           var Store = new Store { address = storeModel.address, postcode = storeModel.postcode, city = storeModel.city, Country = storeModel.Country };
           db.Stores.Add(Store);
           db.SaveChanges();

        return View();
    }

    public ActionResult viewStores()
    {
        var db = new AppContext();

        var query = from b in db.Stores
                    orderby b.storeID
                    select b;

        return View(query.ToList());

    }

    public void Delete()
    {
    }

查看代码

@model IEnumerable <MyProject_04.Models.Store>

@{
   ViewBag.Title = "viewStores";
 }

 <link href="~/Content/kendo/2012.3.1114/kendo.common.min.css" rel="stylesheet" />
 <link href="~/Content/kendo/2012.3.1114/kendo.default.min.css" rel="stylesheet" />
 @Scripts.Render("~/bundles/jquery")
 <script src="~/Scripts/kendo/2012.3.1114/kendo.web.min.js"></script>


  <script type="text/javascript">

   $(function () {
     $(".delete-link").click( function(e){
        e.preventDefault();
        if (confirm("do you want to delete record?")) {
            $(this).closest("tr").hide("slow");
        }
        return false;
    });

           $("#grid").kendoGrid();
   });

  </script>

  <h2>View All the list of stores</h2>


   <table id="grid">
    <thead> 
     <tr>
      <th>Store ID</th>
      <th>Address</th>
      <th>post Code</th>
      <th>City</th>
      <th>Country</th>
      <th>Action</th>
     </tr>
    </thead>

   <tbody>
     @foreach (var item in Model)
      {
        <tr>
         <td>@Html.DisplayFor(modelItem=> item.storeID)</td>
         <td>@Html.DisplayFor(modelItem=> item.address)</td>
         <td>@Html.DisplayFor(modelItem=> item.postcode)</td>
         <td>@Html.DisplayFor(modelItem=> item.city)</td>
         <td>@Html.DisplayFor(modelItem=> item.Country)</td>
         <td>@Html.ActionLink("Delete", "Delete", new { id = item.storeID }, new { @class ="delete-link"})</td>
          </tr>
       }
    </tbody>
  </table>

  <!DOCTYPE html>
   <html lang="en">
   <head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title - My ASP.NET MVC Application</title>
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width" />
    @Styles.Render("~/Content/css")
      <link href="~/Content/kendo/2012.3.1114/kendo.common.min.css" rel="stylesheet" />
    <link href="~/Content/kendo/2012.3.1114/kendo.default.min.css" rel="stylesheet" />
    @Scripts.Render("~/bundles/modernizr")

</head>
<body>
    <div id="container">

     <!--------------Header------------------->
    <div id="header">
        <div class="content-wrapper">
            <div class="float-left">
                <p class="site-title">@Html.ActionLink("MVC Movie", "Index", "Home")</p>
            </div>
        </div>
 </div>

     <!--------------Body------------------->          
  <div id="body">
      @Scripts.Render("~/bundles/jquery")
      <script src="~/Scripts/kendo/2012.3.1114/kendo.web.min.js"></script>

       @RenderSection("featured", required: false)
       <section class="content-wrapper main-content clear-fix">

             @RenderBody()
       </section>


  </div>

     <!--------------Footer------------------->
   <div id="footer">
        <div class="content-wrapper">
            <div class="float-left">
                <p>&copy; @DateTime.Now.Year - My ASP.NET MVC Application</p>
            </div>
        </div>
   </div>
   </div>

    @Scripts.Render("~/bundles/jquery")
    @RenderSection("scripts", required: false)
</body>
 </html>

我已经更改了我的默认布局,但它仍然无法正常工作。

4

1 回答 1

1

是的,那是一团糟。仅将 @Scripts.Render、脚本引用和样式表链接放在 _Layout 视图的 HEAD 中。完成后,MVC 应该看起来非常干净和简单。

至于剑道部分。我知道他们的文档和示例可能会更好,事实上他们的示例通常是最糟糕的方法。但是,请在此站点上搜索人们遇到的其他示例和问题。我认为您可能错过了剑道网格的要点,需要从头开始。获取一个简单的示例,使其工作,然后对其进行扩展。

祝你好运,编码愉快。

于 2013-01-05T23:23:46.167 回答