【发布时间】:2018-09-18 13:49:30
【问题描述】:
当用户浏览它时,这是我的原始网站 http://test/Template/PreviewWebPage/7 其中 7 是传入数据库并获取数据并显示网页的 id
我想问一下如何将 7 更改为其他名称,例如 http://test/Template/PreviewWebPage/Hello Hello 这个词仍然作为一个 id 从数据库中获取数据。
Hello 单词也可以由用户设置并更改它,例如 Food 或用户输入的任何其他单词
我正在使用 asp.net mvc。
这是我的 PreviewWebPage 代码
public ActionResult PreviewWebPage(ShowSectionViewModel model, int id)
{
var item = dc.SECTION.Where(x => x.TEMPLATEID == id).OrderBy(x=>x.ORDERINDEX).ToList();
var item2 = dc.SLIDESHOW.ToList();
List<slideShowClass> slideShowClassList = new List<slideShowClass>();
List<sectionClass> sectionClassList = new List<sectionClass>();
sectionClass sc = new sectionClass();
slideShowClass ssc = new slideShowClass();
for (int i=0; i < item.Count(); i++){
if (item[i].SECTIONTYPE != "Slide Show")
{
sc.SECTIONID = item[i].SECTIONID;
sc.SECTIONIMAGE = item[i].SECTIONIMAGE;
sc.SECTIONNAME = item[i].SECTIONNAME;
sc.SECTIONTEXT = item[i].SECTIONTEXT;
sectionClassList.Add(sc);
}
else
{
for (int j = 0; j < item2.Count(); j++) {
if (item[i].SECTIONID == item2[j].SECTIONID)
{
ssc.SECTIONID = item[i].SECTIONID;
ssc.IMAGEFILE = item2[j].IMAGEFILE;
slideShowClassList.Add(ssc);
}
}
}
}
return View(new ShowSectionViewModel()
{
TemplateId = id,
Sections = item,
SlideShow = item2,
sc = sectionClassList,
ssc=slideShowClassList,
});
}
抱歉我的问题很混乱,因为这是我第一次在 stakoverflow 提问
这是我的路由配置代码
routes.MapRoute( 名称:“预览网页”, url: "模板/PreviewWebPage/{id}", 默认值:新{控制器=“模板”,操作=“PreviewWebPage”,id =“”} );
【问题讨论】:
-
您是否阅读过很多关于网络上关于
RouteConfig类的文章?例如codeproject.com/Articles/624181/Routing-Basics-in-ASP-NET-MVC -
您可能还想澄清一下您使用的是 asp.net mvc 还是 asp.net webforms。
-
请分享最小代码示例
-
当你浏览
http://test/Template/PreviewWebPage/Hello时会发生什么? -
显示与test/Template/PreviewWebPage/7相同的内容。我只是想将可以是任何 ID 号的单词 7 更改为用户将获得一个表单以在其上键入名称的单词
标签: c# asp.net url-rewriting routing url-routing