Adaptive Rendering in ASP.NET MVC - Kazi Manzur Rashid's Blog(weblogs.asp.net)

submitted by jantujantu(1045) 3 years, 1 month ago

ASP.NET MVC comes with different action results for various purpose, but some times, you will find those are not adequate for your scenario, lets consider the following screenshot: When user navigates to a different tab or change the sort order or moves to a different page number, it will load the content as an ajax call, but if the user has JavaScript turned off, it will redirect to a regular url. One solution would be to create separate sets of controller actions that will return either the complete view (in case JavaScript is turned off) or the partial view and use the jQuery load to show the content. But the problem of this approach is that we will be duplicating the same logic for both the actions, moreover we will be returning the unnecessary html tags rather than pure json object that is sufficient for rendering the view. A better solution would be adaptive rendering. If you are not familiar with adaptive rendering then let me clarify it a bit, it is a process where the server responds differently depending upon the browser capability. So it has a broader scope(e.g. mobile devices, text only browsers etc) comparing to our above JavaScript on/off scenario. But for the time being let us only focus on the above, so instead of creating pure html/ajax only version we would like to take the advantage of the browser capability and for this we will create a new action result, the beauty of the new action result is, the controller remains completely unaware of what kind of request it is serving. Lets take a look of the controller action that is serving both:

add a comment |category: |Views: 211

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

No comments so far

information Login or create an account to comment on this story