Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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>
Posted
Updated 3-Nov-17 19:31pm
Comments
Karthik_Mahalingam 3-Nov-17 22:07pm    
you want to redirect to abc.html page ?
Nilesh Thorath 8-Nov-17 9:08am    
yes to the div of the same view
I have a one view name ABC and it has div with id of a , b and c
Now I want to redirect to those div using @html.actionlink

Is there any possible code !

1 solution

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

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


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

So you would need to do

HTML
<a href="@Url.Action("abc", "YourControllerName")#abc">Clcik me</a>
 
Share this answer
 
Comments
Nilesh Thorath 8-Nov-17 9:06am    
your code works like a charm
but can we use it with @html.actionlink method ??
is there any way ?
David_Wimbley 8-Nov-17 10:56am    
I don't think you can use it with action link as that is the html helper for the anchor tag and only has a set number of params/args it will accept.

You can easily write your own html helper that accepts html targeting within the href portion of the attribute via passed in variable.

Here is a link you can follow for building html helpers that a guy used to create a file html helper: http://www.c-sharpcorner.com/UploadFile/3194c4/custom-html-helpers-in-mvc/
Nilesh Thorath 9-Nov-17 13:28pm    
thanks a lot man

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900