-4

我正在尝试使用以下结构/代码创建一个链接按钮:

<%:school => string.Format("<a class='add' href='{0}' title='Add {1} to {4}'><img class='pic2' alt='{2}' src='{3}'/></a>",
                                          Url.Action("AddSchoolToParty", "PartySchool",
                                          new { partyId = Model.PartyId, schoolId = school.SchoolId }),
                                          School.EntityName, string.Empty,
                                          Url.Content("~/Content/images/addImage.png"),
                                          School.EntityName)%>

我得到的错误是:

CS1660:无法将 lambda 表达式转换为类型“字符串”,因为它不是委托类型

这也是用我拥有的信息创建链接的正确格式吗?

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Kids.MVC.Models.ViewModels.SchoolFormViewModel>" %>

<%@ Import Namespace="Kids.Resources" %>
<%@ Import Namespace="Kids.Resources.Entities" %>
<%@ Import Namespace="MvcContrib.Pagination" %>
<%@ Import Namespace="MvcContrib.UI.Grid" %>
<%@ Import Namespace="MvcContrib.UI.Pager" %>
<%: Html.ValidationSummary(true, Message.ValidationErrorSummary, new{@class= "error"}) %>
<%=Html.DatePickerEnable() %>

这是我在不同页面中使用的格式,这是我想在没有列和 string.format 的标签中重写的按钮链接 - 我想知道重写此链接的正确方法。

column.For(
                        school =>
                        string.Format("<a class='add' href='{0}' title='Add {1} to {4}'><img class='pic2' alt='{2}' src='{3}'/></a>",
                                      Url.Action("AddSchoolToParty", "PartySchool",
                                      new { partyId = Model.PartyId, schoolId = school.SchoolId }),
                                      School.EntityName, string.Empty,
                                      Url.Content("~/Content/images/addImage.png"),
                                      School.EntityName)).Encode(false).Sortable(false);
4

1 回答 1

1

试试这样:

<a class="add" href="<%: Url.Action("AddSchoolToParty", "PartySchool", new { partyId = Model.PartyId, schoolId = Model.SchoolId }) %>" title="<%: string.Format("Add {0} to {0}", School.EntityName) %>">
    <img class="pic2" alt="" src="<%: Url.Content("~/Content/images/addImage.png") %>" />
</a>

但是为了避免这种丑陋的标签汤,我建议您编写一个自定义 HTML 帮助程序,这将使这种语法更加清晰。

于 2012-12-13T18:18:22.023 回答