我正在将我的应用程序从asp.net mvc迁移到mvc版本2,并且有以下问题.
<% Html.RenderPartial("PagingControl",Model); %>
它们存在于ascx文件中,如下所示.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BankingDB.Controllers.Utility.IPagedSortedObject>" %> <div class="paging"> <div class="prevIoUs-paging"> <!- error!! -><%= Model.HasPrevIoUsPage ? Html.ActionLink("<<","Index",Model.buildParams(1)) : "<<"%> <%= Model.HasPrevIoUsPage ? Html.ActionLink("<",Model.buildParams(Model.PrevIoUsPageIndex)) : "<"%> </div> <div class="paging-details"> Showing records <%= Model.BaseRecordIndex %> to <%= Model.MaxRecordIndex %> of <%= Model.TotalRecordCount %> </div> <div class="next-paging"> <%= Model.HasNextPage ? Html.ActionLink(">",Model.buildParams(Model.NextPageIndex)) : ">"%> <%= Model.HasNextPage ? Html.ActionLink(">>",Model.buildParams(Model.PageCount)) : ">>"%> </div> </div>
CS0173:条件表达式的类型无法确定,因为’System.Web.Mvc.MvcHtmlString’和’string’之间没有隐式转换
解决方法
Html.ActionLink()现在返回一个MvcHtmlString,而不是一个字符串.这个新类派生自IHtmlString.您不能自动将字符串转换为IHtmlString.
Model.HasPrevIoUsPage ? Html.ActionLink("<<",Model.buildParams(1)) : "<<"
需要改变
Model.HasPrevIoUsPage ? Html.ActionLink("<<",Model.buildParams(1)) : MvcHtmlString.Create("<<")
这个新类将在ASP.NET 4中使用,使“智能”使用新的ASP转义运算符.
<%: Html.ActionLink("My Link","Action","Controller") %> <!-- knows to not HTML-escape,because ActionLink is an IHtmlString --> <%: Model.FirstName %> <!-- short hand notation for <%= Html.Escape(Model.FirstName) %> -->