I am migrating my application from asp.net mvc to mvc version 2 and am having the following issue.
I have paging links << < > >> that I include in each page. Like so:
<% Html.RenderPartial("PagingControl", Model); %>
They exist in an ascx file as follows.
<%@ 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("<", "Index", 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(">", "Index", Model.buildParams(Model.NextPageIndex)) : ">"%>
<%= Model.HasNextPage ? Html.ActionLink(">>", "Index", Model.buildParams(Model.PageCount)) : ">>"%>
</div>
</div>
When I try to access the page I get the error:
CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'System.Web.Mvc.MvcHtmlString' and 'string'
The error is marked above and appears to be with the action link. Including the controller name doesn't help. Any ideas?
Html.ActionLink()
now returns an MvcHtmlString, instead of just a string. This new class derives from IHtmlString. You cannot automatically cast from string to an IHtmlString.
Model.HasPreviousPage ? Html.ActionLink("<<", "Index", Model.buildParams(1)) : "<<"
needs to change to
Model.HasPreviousPage ? Html.ActionLink("<<", "Index", Model.buildParams(1)) : MvcHtmlString.Create("<<")
This new class will be used in ASP.NET 4 to make "smart" use of the new ASP escape operator.
<%: 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) %> -->
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With