1

我第一次开发 ASP.NET MVC3 网站。在我的开发机器上一切正常。

我在我们的测试机器上部署了所有东西。在一些丢失的 DLL 问题之后,该网站似乎可以在以下 url 上运行:

http://localhost/Test%20Website

但是当我单击以下链接时(它是由内联 javascript 创建的,因为我使用的是与问题无关的 Infragistics Grid):

<a href=\"/Patient/Edit/' + val + '\"><img src=\"../Resources/Edit.png\" align=\"left  \"></a>

我收到 HTTP 错误 404.0 - Not Found,这是合乎逻辑的,因为物理路径是:C:\inetpub\wwwroot\Patient\Edit\537

虽然物理路径应该是: C:\inetpub\wwwroot\Test Website\Views\Patient\Edit\537 (至少......我想......不明白 MVC 路由是如何工作的)

顺便说一句,使用 ActionLink HTML 帮助程序创建的链接可以正常工作。所以这有效:@Html.ActionLink("About", "About", "Home") 这有效:@Html.Partial("Search", new SearchModel())

所以,我的问题是,你如何解决这些问题?

ps:资源中的所有图像也不起作用。

回答后更新

对不起,很重要的是要注意这发生在 javascript 函数中作为字符串。那是因为我正在使用 Infragistic 的 JQuery 网格中的 FormatterFunction。好的,这就是我到目前为止所得到的:

"function(val) {return '<a href=\"" + @Url.Content("~/Patient/Edit/" + val) + "\"><img src=\"../Resources/Edit.png\" align=\"left\"></a>'; }"

当前上下文中不存在名称“val”,这是合乎逻辑的。但我不知道如何解决它,因为我对 javascript/Razor/etc 的知识有限……你能帮忙吗?在这种情况下,Val 是它所绑定的列的值。在这种情况下,患者的 ID。

Ego4eg 询问更多代码

它是 Infragistics JQuery 网格。这个网格有一个 FormatterFunction,它有一个字符串作为参数。此字符串需要是一个 javascript 函数。为了给你一个想法,这看起来像:

@(Html.Infragistics()
.Grid(Model)
.ID("grid1")
.AutoGenerateColumns(false)
.Columns(column => {
    //column.For(p => p.ID).FormatterFunction("function(val) {return '<a href=\"/Patient/Edit/' + val + '\"><img src=\"../Resources/Edit.png\" align=\"left\"></a>'; }").Width("25px").HeaderText(" ");
    column.For(p => p.ID).FormatterFunction("function(val) {return '<a href=\"" + @Url.Action("Edit", "Patient", new { id = val }) + "\"><img src=\"../Resources/Edit.png\" align=\"left\"></a>'; }").Width("25px").HeaderText(" ");
    column.For(p => p.ID).FormatterFunction("function(val) {return '<a href=\"/Home/CreateRemark/?patientID=' + val + '\"><img src=\"../Resources/add.png\" align=\"left\"></a>'; }").Width("25px").HeaderText(" ");
    column.For(p => p.FullName).DataType("string").HeaderText("Naam").Width("250px");
    column.For(p => p.Address).DataType("string").HeaderText("Adres").Width("400px");
    column.For(p => p.BSN).DataType("string").HeaderText("BSN").Width("85px");
    column.For(p => p.DateOfBirthAsString).DataType("string").HeaderText("Geboortedatum").Width("85px");
    column.For(p => p.GeneralPractitionerName).DataType("string").HeaderText("Huisarts");
})

希望这可以帮助。

4

2 回答 2

1

最好像这样使用Url.Content

<a href=\"@Url.Content("~/Patient/Edit/" + val)\">
于 2013-04-23T09:29:11.150 回答
0

试试这个:

<a href ="Url.Action("Edit", "Patient", new { id = val })" />
于 2013-04-23T10:32:00.100 回答