Normally, i would write something like this:
<li>#Html.ActionLink("Dashboard", "Index", "Account")</li>
To generate this:
Dashboard
What i want to know is whether it is possible to generate the following HTML
<i class="fa fa-dashboard"></i> Dashboard
Without having to create my own custom TagBuilder class.
Thanks for the help.
You can use UrlHelper.Action to generate the url:
<a href="#Url.Action("Index", "Account")">
<i class="fa fa-dashboard"></i> Dashboard
</a>
Related
I have a context path /userlist and using server side pagination which results in URI like this: http://localhost:8080/userlist/?pageSize=10&page=2.
I am trying to append class to this tag using Thymeleaf dynamically.
<li class="nav-item">
<a class="nav-link" th:with="urls=${new String[]{'/userlist','/userlist/*'}}"
th:classappend="${#arrays.contains(urls, #httpServletRequest.getRequestURI()) ? 'active' : ''}" href="/userlist"
th:href="#{/userlist}">
<span class="nav-icon">
<i class="fas fa-users"></i>
</span>
<span class="nav-link-text"> Manage Users</span>
</a>
</li>
Above works perfectly fine for userlist only. But not for http://localhost:8080/userlist/?pageSize=10&page=2.
Question: What I am missing here?
I can't resolve the 404 I getting and don't understand why I am getting it.
Requested URL
http://localhost:55802/AdminFunctions/BlogMaint/BlogMaint/GetActiveBlogCategorys
Physical Path
F:\Private\Gbng\ProfileAndOrBlog\Development\GbngWebClient\GbngWebClient\AdminFunctions\BlogMaint\BlogMaint\GetActiveBlogCategorys
My link in my cshtml that I click:
<li>
<i class="fa fa-edit fa-fw"></i> Blog Maintenance
My folder structure is:
My controller code method: GetActiveBlogCategorys().
My view folder structure:
Error: not find view:
if you use mvc core
<a asp-controller="BlogMaint" asp-action="GetActiveBlogCategorys"><i class="fa fa-edit fa-fw"></i> Blog Maintenance</a>
otherwise
<a href="#Url.Action("GetActiveBlogCategorys","BlogMaint")">
<i class="fa fa-edit fa-fw"></i> Blog Maintenance
</a>
I don't see you controller, but if you use http post, then need use submit form and this way don't math you.
This question already has answers here:
how to generate Html.ActionLink with icon
(8 answers)
Closed 5 years ago.
I am making an MVC project with basic CRUD functionalities.
In the Index view I have the standard edit and delete links. Which can be clicked for each content item.
<td>
#Html.ActionLink("Edit", "Edit", new { id = item.ContentItemID })>
</td>
<td>
#Html.ActionLink("Delete", "Delete", new { id = item.ContentItemID })
</td>
While this works fine. I want the edit and delete link to be an icon instead of just plain text. I have tried a couple of things but all of them deleted the new { id = item.ContentItemID }
Which I do need to have in my edit and delete so I can select a specific item to edit or delete.
I would like to use the font awesome <i class="fa fa-trash-o" style="font-size:22px;" aria-hidden="true"></i> and the <i class="fa fa-pencil-square-o" style="font-size:22px;" aria-hidden="true"></i>
Is there a possibility for me to do this?
Actionlink is just a generated URL , you can for example concatenate it as an alternative , something like this:
<i class="fa fa-pencil-square-o" style="font-size:22px;" aria-hidden="true"></i>
Html.ActionLink just generates an <a> tag for you. So you can use Url.Action for generating the link.
<a href="#Url.Action("Edit", new { id = item.ContentItemID })>
<i class="fa fa-pencil-square-o" style="font-size:22px;" aria-hidden="true"></i>
</a>
#Html.ActionLink automatically encodes the text you specify. You can implement your own version of that methods that doesn't encode, and keep using the HtmlHelper. This is more reliable than concatenating, since this will not work if routes change in the future.
You can find a sample implementation here.
I use Html.MenuItem helper in asp .net mvc. I want to use html inside link instead of text only. The helper below:
#Html.MenuItem("Announcement", "Index", "Announcement")
generates in html =>
<li> Announcement </li>
but I want to generate an html like =>
<li>
<a href="/Announcement">
<i class="icon-announcement"></i>
<span>Announcement</span>
</a>
</li>
How can I do that?
You can't do that immediately, because the HTML gets stripped if you pass it in as the parameter.
I suggest you do something like the following:
<li>
<a href='#Url.Action("Announcement", "Index")'>
<i class="icon-announcement"></i>
<span>Announcement</span>
</a>
</li>
How can I generate action link with custom html inside.
Like following:
<a href="http://blah-blah/.....">
<span class="icon"/>
New customer
</a>
You can use the UrlHelper class :
<a href="<% =Url.Action("Create","Customers") %>">
<span class="icon"/> New customer
</a>
The MSDN link is here : http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.aspx
For newer versions of .net,
replace
href="<% =Url.Action("Create","Customers") %>"
with
href="#Url.Action("Create","Customers")"
to give something like
<a href="#Url.Action("Create","Customers")">
<span class="icon"/> New customer
</a>