我有一些使用 ASP.NET MVC 的经验,但是几周以来我一直在为 Orchard 开发一个模块。
我无法理解的是,您几乎被强制在 Orchard 中使用 Content Parts 或 Content Types,而我只想从数据库中获取我的数据并以我的方式展示,而不是在某些文章中。
为什么是这样?有什么方法可以像在 ASP.NET MVC 中那样构建模块,而不使用所有 Orchard 的东西?我一直在看几个教程,但它们都是使用部件和驱动程序等。
编辑:
机器.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace PowerAll.Voorraad.Models
{
public class MachineRecord
{
public int Id { get; set; }
public int MachineNumber { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public char PriceType { get; set; }
public decimal Price { get; set; }
public int Year { get; set; }
}
}
迁移.cs
namespace PowerAll.Voorraad
{
public class Migrations : DataMigrationImpl
{
public int Create()
{
SchemaBuilder.CreateTable("MachineRecord", table => table
.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<int>("MachineNumber", column => column.NotNull())
.Column<string>("Title", column => column.NotNull().WithLength(40))
.Column<string>("Description", column => column.WithLength(70))
.Column<char>("PriceType", column => column.NotNull().WithLength(1))
.Column<decimal>("Price", column => column.NotNull())
.Column<int>("Year", column => column.WithLength(4))
);
// Return the version that this feature will be after this method completes
return 1;
}
}
}
机器控制器.cs
namespace PowerAll.Voorraad.Controllers
{
[Themed]
public class MachineController : Controller
{
private readonly IRepository<MachineRecord> machineRecords;
public MachineController(IRepository<MachineRecord> MachineRecords) {
machineRecords = MachineRecords;
}
public ActionResult Index() {
// Here we're just grabbing records based on some fictional "Deleted" flag
var items = machineRecords.Table;
// Items is now an IEnumerable<MachineRecord>
return View(items);
}
}
}
索引.cshtml
@model IEnumerable<PowerAll.Voorraad.Models.MachineRecord>
<ul>
@foreach(var item in Model) {
<li>@item.Id</li>
<li>@item.MachineNumber</li>
<li>@item.Title</li>
<li>@item.Description</li>
<li>@item.PriceType</li>
<li>@item.Price</li>
<li>@item.Year</li>
}
</ul>
Hello from view
'Hello from view' 是可见的,所以我真的进入了我的视野。