如何在html.actionlink中插入图像 - asp.net mvc?
我这样做了,但它不起作用.
<a href="<%= Html.ActionLink("search", "Search", new { searchText = "txtSearch" }, null); %>">
<img alt="searchPage" style="vertical-align: middle;" height="17px"
src="../../Stylesheets/search.PNG" title="search" />
Run Code Online (Sandbox Code Playgroud)
我正在尝试通过ActionLink将对象传递给MVC控制器中的方法.
剃刀语法:
@Html.ActionLink("Export to Excel","ReturnExcelOfViewableResponses",new { SearchObject = Model.SearchObject})
Run Code Online (Sandbox Code Playgroud)
标记中实际显示的内容:
<a href="/EducationAgency/ReturnExcelOfViewableResponses?SearchObject=DTO.SearchObject" tabindex="29">Export to Excel</a>
Run Code Online (Sandbox Code Playgroud)
调用控制器方法就好了,因此没有理由在这里发布.需要做什么才能将实际值传递给actionLink而不是DTO.SearchObject?根据HTML.ActionLink方法,它看起来像我有正确的语法(使用MVC 4).
我有一个ASP.NET MVC 4应用程序.我的应用程序中有一个剃刀视图,它使用List类型作为模型.
@model List<MeetingLog.Models.UserModel>
@{
Layout = null;
}
.
.
.
Run Code Online (Sandbox Code Playgroud)
我正在迭代模型变量,如下所示:
@foreach (var item in Model)
{
<tr>
<td>
@item.Name
</td>
<td>
@item.Surname
</td>
<td>
@Html.ActionLink("Click", "SavePerson", "Meeting", new {model = item, type = "coordinator"}, null)
@Html.ActionLink("Click", "SavePerson", "Meeting", new {model = item, type = "participant"}, null)
</td>
</tr>
}
Run Code Online (Sandbox Code Playgroud)
我需要将两个变量传递给具有操作链接的SavePerson操作.第一个是当前的UserModel,第二个是名为type的字符串变量.但在我的行动中,第一个参数是null.但字符串参数正确.我怎样才能做到这一点?
我有一个actionlink,我需要它来传递包含连字符( - )的参数.无法更改名称约定.我该怎么做呢?
<li>@Html.ActionLink("abc", "abc", "abc", new { area = "",sap-ie="Edge" }, new { id = nav_abc"})</li>
Run Code Online (Sandbox Code Playgroud)
这个给我一个错误"无效的匿名类型声明符",因为它包含连字符.基本上我需要actionlink来生成如下的html.
<a href=".../abc?sap-ie=Edge" id="nav_abc" >abc</a>
Run Code Online (Sandbox Code Playgroud) 我有以下内容ActionLink:
@Html.ActionLink("Upload", "Upload", "File")
Run Code Online (Sandbox Code Playgroud)
但当我将鼠标悬停在链接上时,浏览器中显示的网址是http://localhost:44334/Upload.这个网址中的控制器在哪里?奇怪的是,点击网址会将我带到我的File/Upload视野,但更奇怪的是,浏览器地址栏中显示的网址是https://localhost:44334/Upload.
的ActionLink是页面上Home/Explorer,所以据我所知控制器名通常是必要的.
为什么ActionLink助手会遗漏控制器名称,为什么链接仍然有效?我尝试使用缓存清除刷新页面,没有区别.我不知道还有什么可以做,除了它可以工作,但我担心这是一些怪癖,当我部署我的网站时它将不再起作用.
我的路由在Startup类的Configure方法中仍然是标准的,开箱即用的:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)
奇怪的是,我现在已经Download在HTML文件表的每一行添加了一个链接,如下所示:
@Html.ActionLink("Download", "Download", "File", new { filePath = file.Path })
Run Code Online (Sandbox Code Playgroud)
此链接也会在没有控制器名称的情况下呈现,例如:
https://localhost/Download?filePath=....
Run Code Online (Sandbox Code Playgroud) c# html.actionlink asp.net-core-mvc asp.net-core asp.net-core-routing
MvcContrib GridModel:是否可以在GridModel中执行ActionSyntax 我已经阅读了这篇文章,它非常有用,但我无法应用它.我不知道在最新的MVCContrib中,他们删除了".Action()",因为我无法访问它.
有没有我可以将编辑链接的ActionLink放入网格模型中?
谢谢
我正在尝试使用Ajax调用创建一个MVC网站.我没有直接使用jquery的问题,但是当我使用@ Ajax.ActionLink时,我没有得到我想要的结果.这是我的观点:
<script type="text/javascript">
function deleteComment(id) {
$.post(
"/Role/AjaxTest",
//{ id: id },
function (data) {
$("#testtarget").html(data);
});
}
</script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<h2>TITLE</h2>
<p>
@Ajax.ActionLink("Ajax Test", "AjaxTest", "Role", new AjaxOptions{UpdateTargetId="testtarget",HttpMethod = "Get" , InsertionMode = InsertionMode.Replace })
</p>
<table>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.RoleName)
</td>
<td>
<a onclick="deleteComment('@item.RoleId'); return false;" href="#">Delete</a>
@Html.ActionLink("Delete", "Delete", new { id=item.RoleId })
</td>
</tr>
}
</table>
<div id="testtarget">Test Div</div>
Run Code Online (Sandbox Code Playgroud)
这是我的Controler数据:
public string AjaxTest()
{
return "Some random text"; …Run Code Online (Sandbox Code Playgroud) 在asp.net mvc中,我有一个带有名称索引的视图,它将一个html表显示为网格.假设这是我的html表:
<table>
<tr>
<th>
Caption
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Caption)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.CityId }) |
@Html.ActionLink("Details", "Details", new { id=item.CityId }) |
@Html.ActionLink("Delete", "Delete", new { id=item.CityId }) |
</td>
</tr>
}
</table>
Run Code Online (Sandbox Code Playgroud)
现在我想把它放在@Html.DisplayFor(modelItem => item.Caption)文本中@Html.ActionLink("Edit", "Edit", new { id=item.CityId })
但我从mvc给出一个错误.
在我的控制器中,我有这个:
ViewBag.lstIWantToSend= lstApps.Select(x => x.ID).ToList(); // creates a List<int> and is being populated correctly
Run Code Online (Sandbox Code Playgroud)
我想将该列表传递给另一个控制器..所以在我看来我有:
@Html.ActionLink(count, "ActionName", new { lstApps = ViewBag.lstIWantToSend }, null)
Run Code Online (Sandbox Code Playgroud)
控制器中的方法:
public ActionResult ActionName(List<int> lstApps) // lstApps is always null
Run Code Online (Sandbox Code Playgroud)
有没有办法将整数列表作为路由值发送到控制器方法?
得到以下错误..
编译器错误消息:CS1973:'System.Web.Mvc.HtmlHelper'没有名为'ActionLink'的适用方法,但似乎有一个名称的扩展方法.无法动态分派扩展方法.考虑转换动态参数或调用扩展方法而不使用扩展方法语法.
在MVC应用程序中,我试图使用字典条目的键作为链接的链接文本,但我得到错误.
这是我遇到错误的行......我尝试用@ item.Key和其他各种方法替换item.Key.
@Html.ActionLink(item.Key,"ExpandFolder","Home",new {path=item.Key },null)
Run Code Online (Sandbox Code Playgroud)
我的整个视图代码看起来像这样......
<form id="ViewFiles" method="post" action="Index">
<ul>
@foreach (var item in @ViewBag.filesFolders)
{
if (item.Value == "folder")
{
<li>
@Html.ActionLink(item.Key,"ExpandFolder","Home",new {path=item.Key },null)
</li>
}
else if (item.Value == "file")
{
<li><a href="">FILES-@item.Key</a></li>
}
}
</ul>
</form>
Run Code Online (Sandbox Code Playgroud) html.actionlink ×10
asp.net-mvc ×6
c# ×4
razor ×4
.net ×1
asp.net-ajax ×1
asp.net-core ×1
grid ×1
html ×1
image ×1
model ×1
mvccontrib ×1
routevalues ×1