php mvc url 参数,C#-积累-在ASP.NET MVC 两种URL请求-带参数-Resultful-RouteConfig-路由配置-带问号...

调试时尽量关闭自定义错误页(Web.config)

方式一:使用?带参数

// localhost:29035/Home/Detail?designId=17

public ActionResult Detail(string designId)

{

if (string.IsNullOrWhiteSpace(designId))//无参数时跳转到首页

{

return RedirectToAction("Index", "Home");

}

ViewBag.DesignId = designId;

ServerResponse qer = DesignDetialDAL.GetBaseinfo(designId);

if (qer.IsSuccess())

{

OpusEntity qe = qer.GetResult();

ViewBag.BaseInfo = qe;//含有url

return View("~/Views/Home/Datail.cshtml");

}

return RedirectToAction("notfound", "Home", new { ErrCode = 404, ErrMsg = "此详情页未找到" });//404

}

方式二:RouteConfig配置路由(注: 方式一中的控制器也是要写的)

// localhost:29035/Home/Detail/17

App_Start/RouteConfig.cs 文件

public class RouteConfig

{

public static void RegisterRoutes(RouteCollection routes)

{

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(

name: "Default",//唯一

url: "{controller}/{action}",

defaults: new { controller = "Home", action = "Index" }

);

routes.MapRoute(

name: "DesignDetail",

url: "{controller}/{action}/{designId}",

defaults: new { controller = "Home", action = "Detail",id = UrlParameter.Optional }

);

}

}

更多解释

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值