I have following code
#Html.Pager((IPagination)Model.FoundUsers).Last("<span class=\"last\"> </span>").First("<span class=\"first\"> </span>").Next("<span class=\"next\"> </span>").Previous("<span class=\"prev\"> </span>")
But it renders encoded and shows <span class="next"> on page.
I tried to used Html.Raw as suggested in Problem with razor view and mvccontrib grid pagination or How to make a pager with MVCContrib and Razor?
but it still does not work for me.
What am I doing wrong ?
I would assume that you are using MvcContrib v2 with Mvc4 (or possibly Mvc3)?
Either manually download the newer libraries from http://mvccontrib.codeplex.com or use the Raw method. So instead of this:
#Html.Pager((IPagination)Model.FoundUsers).Last("<span class=\"last\"> </span>").First("<span class=\"first\"> </span>").Next("<span class=\"next\"> </span>").Previous("<span class=\"prev\"> </span>")
You would instead have:
#Html.Raw(Html.Pager((IPagination)Model.FoundUsers).Last("<span class=\"last\"> </span>").First("<span class=\"first\"> </span>").Next("<span class=\"next\"> </span>").Previous("<span class=\"prev\"> </span>"))
Perhaps it's because I am working in VB, but I had to get the appropriate string from the Pager object:
#Html.Raw(Html.Pager(Model).ToString)
I'm using MvcContrib 2.0.95 with MVC 3.
Related
Am working on an Asp.Net MVC Web application, I am using a theme to replace the default theme and I would like to use #html.ActionLink() to generate a link. My problem is that the theme requires that I nest another element in the html link tag that will be automatically be generated. How do I nest elements using razor syntax?
I don't think that you can nest elements in razor syntax.
Solution for your problem would be to use #Url.Action() inside href property of a tag like this:
I'm currently using PagedList (https://github.com/TroyGoode/PagedList/) to manage my paging in an ASP.NET MVC application.
As of today I have started converting some parts of the application to use AJAX, which ASP.NET MVC makes quite easy.
The first problem I have run into however is that the PagedList.MVC helper #Html.PagedListPager is not in any way compatable with unobtrusive AJAX.
All I really need to do is add some attributes to the paging links (see below) and the rest would be taken care of automatically. PagedListPager does not provide any way to do this however.
data-ajax="true" data-ajax-mode="replace" data-ajax-update="#SearchResults"
Has anyone run into this and found an elegant solution?
I have added support for unobtrusive AJAX:
https://github.com/TroyGoode/PagedList/issues/26#issuecomment-6471793
I believe this may be the most elegant solution.
#Html.PagedListPager((IPagedList)Model.Articles, page => Url.Action("Index", new { s = Model.SearchString, page = page }))
<script>
var pages = $('#pages a[href^="/"]');
pages.attr('data-ajax', 'true')
.attr('data-ajax-mode', 'replace')
.attr('data-ajax-update', '#SearchResults')
.attr('data-ajax-method', 'post');
</script>
Quick jQuery hack to add the necessary attributes to all links in order for them to be picked up by the unobtrusive ajax module.
The [href^="/"] part ensures that only the clickble links will be modified. If you don't use this, the greyed out Previous link will be clickable.
What is the benefit to using Html.BeginForm?
We're having some issues related to html helpers and razor generator view testing and I'm struggling to see the benefit which would stop us going back to old skool form tags.
Has anyone got an argument for or against either?
by old skool i mean:
<form action="#Url.Action('Blah')">
The Html.BeginForm is useful because it generates the url using the routes defined in the Global.asax. (or you can extend it with your own code)
Using the old tag is neither worst or best in my opinion. You simply have to generate your url manually or using the Url helper. In the end the html in the page will be the same
<form ....>
html
</form>
Html.BeginForm also implements IDisposable, meaning the form must be closed properly. It's a minor thing, perhaps, but not closing Html.BeginForm produces a run-time error, where an unclosed <form> tag does not.
no there is no difference , the form tag just use the routing to generate the url , so if you use #Url.Action you are good to go
there is even books use that way a plain old tag and a url helper to generate the route
ASP.NET MVC Website Programming is an example
Edit
**
starting from Mvc 4 there is no difference , prior to Mvc 4 , Mvc 3 for example require the Html.BeginForm to make the javascript unobtrusive validation to work
I'm wondering does the latest release of MvcContrib work with the Razor view engine? I referenced the MvcContrib assembly and the FluentHtml assembly, then I added the required namespace to the ~/View/Web.config as suggested here by Darin. But still, no matter how much I try use the FluentHtml extensions in my views, it doesn't work. (nothing shows up in intellisense when I start with a dot after the html helper)
Am I missing anything?
P.S: this is the first time I use MvcContrib.
I wrote a short blog that post covers using FluentHtml with Razor.
Regarding intellisense, you will only get intellisense for FluentHtml methods on "#this." (not "#Html.") and it only list the strong-typed helpers on views that implement IViewModelContainer<T> (such as ModelWebViewPage<T>). Another possible issue is Resharper. There is a workaround for that.
I´m using mvccontrib and following darin answer it has to work. The steps I followed were:
copy-pasted in bin folder mvccontrib.dll and mvccontrib.fluent.dll
make a reference in references to those dll creating a reference for mvccontrib and mvccontrib.fluent.
two namespaces with the following names:
add namespace="MvcContrib"
add namespace="MvcContrib.FluentHtml"
in my controller I include using MvcContrib.Pagination;
finally I used in my view:
#using MvcContrib.UI.Pager
#using MvcContrib.Pagination
and rebuild.
hope it helps..
What I mean by that is a type element that will have a label based on a value in my viewModel and also be able to submit that value back up to the viewModel so it can grab new results based on Current Page and Page Size. This is for creating a gridview in MVC that supports pagination.
None of the examples I've seen of MVC so far have had anything resembling a gridview. It's important that I create my own paging and not use any built in paging mechanisms or third party controls or html helpers or the like
I'd go with ActionLink. To build Urls you can either use Url.Action or Html.BuildUrlFromExpression(c => c.conTrollerAction)
If you use T4MVC, you will get some nice helpers that do exactly what you are looking for.
Something along the lines of:
<a href="<%: Url.Action(MVC.MyController.MyAction(Model.ActionMethodParam1, Model.ActionMethodParam2)) %>">
You can also use the Html.ActionLink helper:
<%: Html.ActionLink("Link Name", MVC.MyController.MyAction(Model.ActionMethodParam1, Model.ActionMethodParam2)) %>
T4MVC is a great little library that I use in every MVC app.