我如何在@ url.action中使用# [英] How do I use # in @url.action

查看:81
本文介绍了我如何在@ url.action中使用#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的HTML模板继承到mvc

但我找不到将这个html代码转换为MVC的方法



< a href =abc.html#abc>



我尝试过:



i已经尝试了

I want to inherit my HTML template into mvc
but I couldn't find a way to convert this html code to MVC

<a href="abc.html#abc>

What I have tried:

i have tried

<li>@html.actionlink("abc","abc@abc","abc")</li>

推荐答案

我假设当你说abc.html时你指的是MVC frameowrk中控制器中的动作。如果你想直接引用.html,你就不会在那种情况下使用Html.ActionLink。



假设你有Index.cshtml和About.cshtml在HomeController中。



要在index.cshtml的URL中引用id为testdiv的div(在你的例子abc.cshtml中,id为abc)你会执行以下操作



I'm assuming when you say abc.html you're referring to the action in a controller within the MVC frameowrk. If you want to reference the .html directly you're not really using Html.ActionLink in that situation.

Lets say you have Index.cshtml and About.cshtml both within the HomeController.

To reference div with id of "testdiv" in a URL from index.cshtml (in your example abc.cshtml with id of abc) you would do the following

<a href="@Url.Action("About", "Home")#testdiv">Click me</a>





这会产生一个点击我链接,其href值为/ home / about#testdiv。



所以你需要做





Which would generate a link of "Click Me" with a href value of /home/about#testdiv.

So you would need to do

<a href="@Url.Action("abc", "YourControllerName")#abc">Clcik me</a>


这篇关于我如何在@ url.action中使用#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆