0

我开始为 ASP.NET MVC 4 使用完整的 Kendo UI。我已经创建了我需要的数据库和模型,但现在我希望能够处理(索引、创建、删除、详细信息和编辑)每个选项卡内容内的实体。但我不知道如何在 de tabstrip 中做到这一点。(我从已经有 HomeController 的 Internet 应用程序模板开始)

到目前为止,我的代码是:

/Views/首页/索引

@{
    ViewBag.Title = "Home Page";
}

@(Html.Kendo().TabStrip()
                .Name("tabstrip")
                .Items(items =>
                {
                    items.Add().Text("Students").Selected(true).LoadContentFrom("Index","Student"); //Add item with text "Students"
                    items.Add().Text("Teachers"); 
                    items.Add().Text("Schools"); 
                })
)

/控制器/学生控制器

 public class StudentController : Controller
    {
        private MiniSIGEdb db = new MiniSIGEdb();

        //
        // GET: /Student/

        public ActionResult Index()
        {
            var students = db.Students.Include(s => s.Person).Include(s => s.School);
            return PartialView(students.ToList());
        }

        //
        // GET: /Student/Create

        public ActionResult Create()
        {
            ViewBag.Person_id = new SelectList(db.People, "id", "FirstName");
            ViewBag.School_id = new SelectList(db.Schools, "id", "City");
            return PartialView();
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }

/视图/学生/索引

@model IEnumerable<MiniSIGEweb.Models.Student>
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Course)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Person.FirstName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.School.City)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Course)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Person.FirstName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.School.City)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.id }) |
            @Html.ActionLink("Details", "Details", new { id=item.id }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.id })
        </td>
    </tr>
}

</table>

到目前为止,我能够显示 de Index 视图(作为部分视图),但是当我单击“新建”时,创建视图不会在标签条内呈现?我怎样才能做到这一点?

4

1 回答 1

1

由于您的 tabstrip 加载了 Ajax,这意味着其他每个用于编辑、创建、删除的视图也应该加载 Ajax。

您可以查看MVC Ajax 链接助手。在 tabstrip 内创建一些结果元素,该元素应使用 Ajax 加载的内容进行更新。

于 2013-03-13T20:15:26.440 回答