开发者

web deploy url paths mvc

开发者 https://www.devze.com 2023-03-15 16:25 出处:网络
When I deploy my mvc app I am having difficulty getting my paths to work correctly when moving between pages (views).

When I deploy my mvc app I am having difficulty getting my paths to work correctly when moving between pages (views).

Basically in my development environment my landing page is localhost:1910/ whereas when I deploy it, my landing page is localhost/ITSMngr.

Therefore all my links keep missing the ITSMngr section. eg If I have a link such as:

<a href="/DataBaseMng/Edit?id=@signData.SignDataId" >

where DataBaseMng is the name of a controller and Edit the action, it works fine in 开发者_如何学Pythonmy dev environment because it will ultimately map it to localhost/DataBaseMng/Edit?id=2 or something. Whereas when deployed it will try to map to the same path but won't work because it misses the ITSMngr section. ie it should map to localhost/ITSMngr/DataBaseMng/Edit?id=2

Is there a way to set that up by default somewhere so it always will put in ITSMngr for me? I've tried changing the map routes in Global.asax.cs but it doesnt' work - not that I'm 100% convinced I'm doing it correctly.

Removing the / at the beginning of my links will work once, but when you navigate back again, it's internal paths are all shot and it might lo


In an MVC application you should use the built-in functions to generate URLS instead of hard coding them. This should take care of it all for you, and make use of the Routes defined in your global.ascx

Instead of:

<a href="/DataBaseMng/Edit?id=@signData.SignDataId" >

Use:

<a href="@Url.Action("Edit", "DataBaseMng", new { id = signData.SignDataId })" >

If you want to reference something using the Url rather than the Action helper method (not really recommended) then use:

@Url.Content("~/DataBaseMng/Edit?id=" + signData.SignDataId.ToString())

Note the ~ which asp .net will map to wherever you've installed the application

0

精彩评论

暂无评论...
验证码 换一张
取 消