【发布时间】:2018-07-25 16:57:16
【问题描述】:
我有一张桌子,我想用它来制作目录。
我的桌子是这样的:
Id Product Description Price
我将创建一个索引,在其中列出所有产品及其名称,并通过链接链接到我有其描述的视图,我知道该怎么做,但我不知道怎么做使索引的每个链接自动或通用接收驱动程序例如:
<a href="https://example.tld/product/id/name-of-product">name of product</a>
我认为我不必创建控制器产品名称和另一个产品名称我想我发送 控制器 产品的地方有一些通用的东西 acion 索引
示例:ProductController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MySite.Controllers
{
public class ProductyController: Controller
{
// GET: Product
public ActionResult Index (int id, string productstring)
{
return Content (productstring + "example fooo bar ..");
// or
return View ("my_generic_view_styled_css.cshtml");
}
}
}
这样当你输入https://example.tld/product/id/foo-bar-any
我用我的信息返回了我的 index.cshtml,我知道如何填写它,但我不知道如何处理 SEO 的网址
我的问题是没有用链接创建索引,问题是直接点击或转到url没有错误404
【问题讨论】:
-
那么为什么不在
Index函数中创建一个包含所有链接和描述的视图模型,以及一个创建 html 的视图呢?你知道,就像任何其他普通视图/视图模型一样。 -
我的问题不是用链接创建索引,问题是直接点击或者去url没有错误404
标签: c# model-view-controller clean-urls