@ HTML.ActionLink和@ URL.Action不起作用?

时间:2017-02-27 03:07:50

标签: c# asp.net-mvc razor

我必须在这里遗漏一些简单的东西,但我不明白我的Razor页面中的链接是怎么回事?

我已经尝试了这两个来创建一个指向我的Controller / ActionResult的链接,它应该是Gallery / Index。

static void Main(string[] args) {
    csProcess = Process.GetProcessesByName("notepad").FirstOrDefault();
    if (csProcess == null) { return; } // notepad isn't running
    modules = csProcess.Modules;
    foreach(ProcessModule module in modules) {
        if (module.ModuleName == "client.dll") {
            int ClientDLL = Mem.Module("client.dll");
        }

        int LocalPlayer = ReadProcessMemory(ClientDLL + m_dwLocalPlayer);
        int LocalTeam = ReadProcessMemory(LocalPlayer + m_iTeamNum);
        int CrossHairID = ReadProcessMemory(LocalPlayer + m_iCrossHairID);
        int EmemyinCrossHair = ReadProcessMemory(ClientDLL + m_dwEntityList +
            ((CrossHairID - 1) * EntLoopDist));
        int EnemyTeam = ReadProcessMemory(EnemyInCrossHair + m_iTeamNum);
        int EnemyHealth = ReadProcessMemory(EnemyinCrossHair + m_iHealth);

        if (EnemyHealth > 0 && EnemyTeam != LocalTeam) {
            mouse_event(MOUSEEVENTF_LEFTDOWN, Control.MousePosition.X,
                Control.MousePosition.Y, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, Control.MousePosition.X,
                Control.MousePosition.Y, 0, 0);
        }
    }
}

当我使用它们并查看页面源时,它会创建以下链接。

@Html.ActionLink("Click Here", "Index", "Gallery", null, null)

<a href="@Url.Action("Index","Gallery")">Click here</a>

如果单击其中任何一个,我会收到以下错误消息:

<a href="/Gallery">Click Here</a>

<a href="/Gallery">Click here</a> to see examples of our work.

但是,如果我直接浏览/ Gallery / Index,那么页面工作正常。

为什么这些ActionLink或UrlAction不会创建类似&#34; /图库/索引&#34;的链接?

1 个答案:

答案 0 :(得分:0)

根据您的需要尝试使用@Html.ActionLink,如下所示:

<强> 默认值:

@Html.ActionLink("Index", "Gallery") 


使用按钮:

<button onclick="location.href='@Url.Action("Index", "Gallery")';
    return false;">Click Here</button>


使用参数:

<button onclick="location.href='@Url.Action("Index", "Gallery",new { Model.Id})';
    return false;">Click Here</button>

<input type="button" title="Click Here" value="Click Here" 
    onclick="location.href='@Url.Action("Index", "Gallery", new { id = item.Id })'" />


使用超链接:

<a href="/Gallery/Index/123">Click Here</a>


使用图片

<a href="@Url.Action("Index", "Gallery", new { id = item.Id })" title="Click Here">
<img src="../Content/Images/gallery.png" />

希望这会有所帮助......