Thursday, March 17, 2016

Load Partial Content Async

http://improve-mvc-perf-with-async-views.azurewebsites.net/async

View/Index
<script src="~/Scripts/site.js"></script>
<p>
    Below are three sections. Initially they are all computed during the request. We are moving
    the slow ones to their own actions with partial views and loading them via JavaScript asynchronously.
</p>

<div class="news">
    <h3>News (slow)</h3>
    <div class="partialContents" data-url="/AsyncPageLoading/One">
        <img src="http://www.xiconeditor.com/image/icons/loading.gif" /> Loading ...
    </div>
</div>

<div class="popular">
    <h3>Most Popular (slow)</h3>
    <div class="partialContents" data-url="/AsyncPageLoading/two">
        <img src="http://www.xiconeditor.com/image/icons/loading.gif" /> Loading ...
    </div>
</div>
--------------------------------------------

Controller

  // GET: AsyncPageLoading
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult One()
        {
            Thread.Sleep(5000);
            return PartialView();
        }

        public ActionResult Two()
        {
            return PartialView();
        }
------------------
partial view

<h2>One</h2>
Hi
In our previous program we have used Microsoft date picker and we created our own user control and there we made the feature where user can select the date from the picker or user can type the date into the date picker and on the even leave we will format the date according to the format we need. if user enter an invalid date on the leave even we will show a error (validator) to show that the date entered is invalid.

Now in our new module we have used the Telerik date picker and can we do the similar where we allow the user type the date, when you check the attached video in our old date picker as soon as the user click in to the date piker control the date format ("/") get removed and only the numbers left so user can delete and retype.

Since user used to this feature and we want to do the same with the Telerik date picker can you please give me a small sample working code that I can achieve similar feature.

--------------------------
Javascript

/// <reference path="../Scripts/jquery-1.8.2-vsdoc.js" />

var site = site || {};
site.baseUrl = site.baseUrl || "";

$(document).ready(function (e) {

// locate each partial section.
// if it has a URL set, load the contents into the area.

$(".partialContents").each(function(index, item) {
var url = site.baseUrl + $(item).data("url");
if (url && url.length > 0 ) {
$(item).load(url);
}
});

// DEMO ONLY - JUST IGNORE
// Just to make the loading time obvious....
$("a.nav").click(function() {
$("body").html("");
});

});






No comments:

Post a Comment

Sql server row level policy