
Figure 1:
Beginning
IML: contributed greatly to a simpler way of creating ajax application
due to the ability to divide complex.
Veiws: into simple ones remarkably reducing the code and to increasing
noteworthily Action in Controller.
MVD: ( model view dispatcher ) is a design pattern to execute a
Command/Query without writing an Action For example:
- private void btn_load_Click(object sender, EventArgs e)
- public ActionResult Details(GetUserDetailsQuery query)
- {
- var model = dispatcher.Query(query);
- return IncView(model);
- }
- @Html.When(JqueryBind.InitIncoding)
- .Do()
- .AjaxGet(Url.Action("Details","Users"))
- .OnSuccess(dsl = > dsl.Self().Core().Insert.Html())
- .AsHtmlAttributes()
- .ToDiv()
Write less, do more
Consider next a new View code
- Html.When(JqueryBind.InitIncoding)
- .Do()
- .AjaxGet(Url.Dispatcher()
- .Query(new GetUserDetailsQuery())
- .AsView("~/Admin/Views/Users/Details.cshtml"))
- .OnSuccess(dsl = > dsl.Self().Core().Insert.Html())
- .AsHtmlAttributes()
- .ToDiv()
- Url.Dispatcher()
- .Query(new GetUserDetailsQuery())
- .AsView("~/Admin/Views/Users/Details.cshtml")
The present code will work without writing an Action significantly saving time on development and maintenance.
No More MVC
- Create a DispatcherController (the name is of importance) inherited from the DispatcherControllerBase(set as default by version 1.1).
- public class DispatcherController : DispatcherControllerBase
- {
- public DispatcherController()
- : base(typeof(T).Assembly)
- { }
- }
- Query(string incType, string incGeneric, bool? incValidate)
- Render(string incView, string incType, string incGeneric)
- Push(string incType, string incGeneric)
- Composite(string incTypes)
- QueryToFile(string incType, string incGeneric, string incContentType, string incFileDownloadName)
Url.Action("Push", "Dispatcher", new { incType = typeof(Command).Name } )One can use the Url.Dispatcher to simplify building of url address
Url.Dispatcher().Push(new Command())
Application
MVD covers most of the frequent scenario in web-development powered by asp.net mvc. Note: Download. the examples
- Push for a single command
- Html.When(JqueryBind.Click)
- .Do()
- .AjaxPost(Url.Dispatcher().Push(new AddUserCommand
- {
- Id = "59140B31-8BB2-49BA-AE52-368680D5418A",
- Name = "Vlad"
- }))
- .OnSuccess(dsl = > dsl.With(r = > r.Id(containerId)).Core().Insert.Html())
- .AsHtmlAttributes()
- .ToButton("Run")
Note: Selector can be used as values for parameters
- Push for a single generic command
- Html.When(JqueryBind.Click)
- .Do()
- .AjaxPost(Url.Dispatcher().Push(new AddEntityCommand<T>()))
- .OnSuccess(dsl = > dsl.With(r = > r.Id(containerId)).Core().Insert.Html())
- .AsHtmlAttributes()
- .ToButton("Run")
Note: push returns the result and there is an array comprised the results of each command for the composite
- Push for a command composite
- Html.When(JqueryBind.Click)
- .Do()
- .AjaxPost(Url.Dispatcher()
- .Push(new AddUserCommand { Id = "1", Name = "Name" })
- .Push(new ApproveUserCommand { UserId = "2" }))
- .OnSuccess(dsl = > dsl.With(r = > r.Id(containerId)).Core().Insert.Html())
- .AsHtmlAttributes()
- .ToButton("Run")
Note: be aware that in case parameter-names match, the value will be the same and from the last, and an extra prefix may be attached to the name in these situations.
- Query as Json
- Html.When(JqueryBind.Click)
- .Do()
- .AjaxPost(Url.Dispatcher()
- .Query(new GetCurrentDtQuery())
- .AsJson())
- .OnSuccess(dsl = > dsl.With(r = > r.Id(containerId)).Core().Insert.Html())
- .AsHtmlAttributes()
- .ToButton("Run")
- Query ( generic) as Json
- Html.When(JqueryBind.Click)
- .Do()
- .AjaxPost(Url.Dispatcher()
- .Query(new GetTypeNameQuery<T>())
- .AsJson())
- .OnSuccess(dsl = > dsl.With(r = > r.Id(containerId)).Core().Insert.Html())
- .AsHtmlAttributes()
- .ToButton("Run")
- Query as View
- Html.When(JqueryBind.Click)
- .Do()
- .AjaxPost(Url.Dispatcher()
- .Query(new GetUserQuery())
- .AsView("~/Views/Home/User.cshtml"))
- .OnSuccess(dsl = > dsl.With(r = > r.Id(containerId)).Core().Insert.Html())
- .AsHtmlAttributes()
- .ToButton("Run")
Note: View path is not built under the Controller in asp.net mvc, but the site root directory, to create any folder structure for View storage.
- Query as File
<a href="@Url.Dispatcher().Query(new GetFileQuery()).AsFile(incFileDownloadName: "framework")">Download</a>
Note: building a File requires the Query to return byte ( byte[] ) array as a result
- Model as View
- Html.When(JqueryBind.Click)
- .Do()
- .AjaxPost(Url.Dispatcher()
- .Model(new GetUserQuery.Response
- {
- Id = "2",
- Name = "Incoding Framework"
- })
- .AsView("~/Views/Home/User.cshtml"))
- .OnSuccess(dsl = > dsl.With(r = > r.Id(containerId)).Core().Insert.Html())
- .AsHtmlAttributes()
- .ToButton("Run")
Note: if the query is not completed via Ajax, it will result in ContentResult rather than JSON
- View
- Html.When(JqueryBind.Click)
- .Do()
- .AjaxPost(Url.Dispatcher().AsView("~/Views/Home/Template.cshtml"))
- .OnSuccess(dsl = > dsl.With(r = > r.Id(containerId)).Core().Insert.Html())
- .AsHtmlAttributes()
- .ToButton("Run")
- Selector urlTemplate = Url.Dispatcher().AsView("~/Views/Medication/Medication_Table_Row_Tmpl.cshtml").ToAjaxGet();
- dsl.Self().Core().Insert.WithTemplate(urlTemplate).Append();
What has to be done if
Notice that lack of the Controller does not allow using attributes implemented in different scripts. Let us consider the frequent tasks virtually applied for any site, namely, a test for authorization. Within ASP.NET MVC the task is solved using attributes to mark those Actions (or Controller) where validation logic is described, the present task can be solved in different ways in MVD:
- Mark with a DispatcherController attribute and in an attribute code. This method is convenient if writing CRM system and performing all the actions with authorization.
Note: the current requested address can be checked in the Allow List in the attribute code i.e. executing the code if the address is not included
in the List.
- Use Dispatcher Event capabilities described in the article.
Note: the Command/Query can be marked with attributes that is similar to the standard ASP.NET MVC.
- Implement the test for a client.
- Html.When(JqueryBind.InitIncoding)
- .Do()
- .AjaxGet(Url.Dispatcher()
- .Query(new IsAuthorizeDeviceQuery
- {
- DeviceId = Selector.Incoding.Cookie(OnAddCookieEvent.DeviceIdKey)
- })
- .AsJson())
- .OnSuccess(dsl = >
- {
- dsl.Self().Core().Break
- .If(builder = > builder.Data(r = > r.Value == false));
- //some code if authorize ok
- })
- .OnBreak(dsl = > dsl.Self().Core().Trigger.Invoke("SignIn"))
- .When("SignIn")
- .Do()
- .AjaxGet(Url.Dispatcher().AsView("~/Areas/Client/Views/Account/SingIn.cshtml"))
- .OnSuccess(dsl = > dsl.With(r = > r.Id(dialogId))
- .Behaviors(inDsl = >
- {
- inDsl.Core().Insert.Html();
- inDsl.JqueryUI().Dialog.Open(options = >
- {
- options.Title = "Sign in device";
- });
- }))
- .AsHtmlAttributes()
- .ToDiv()
The stepwise algorithm:
- After loading the element ( InitIncoding ), issue an Ajax query ( ine 3).
- Check the result via OnSuccess, if the user is not authorized choose Break.
- If it is OnBreak, choose trigger for SignIn “leg” and give the dialogue with an authorization form.
- If the code passes OnBreak, perform the actions to run page scripts.
The code deals with most scripts and does not limit the spectrum (roles, rights, etc ) for tests, there is also а possibility to perform various tests depending on a page, i.e. constructing Home/Index and Dashboard/Index with different codes.

Santhakumar MunuswamyPosted Sep 12, 2015, 3:08 AM
Thanks for nice article:)
Mohammed IbrahimPosted Sep 12, 2015, 1:49 AM
nice information
Pankaj Kumar ChoudharyPosted Sep 11, 2015, 1:22 PM
Nice Article Sir........
RakeshPosted Sep 11, 2015, 10:25 AM
Good work sir
Nilesh JadavPosted Sep 11, 2015, 9:22 AM
This is really nice one sir
Karthikeyan KPosted Sep 11, 2015, 7:37 AM
Awesome one :)
Harshad PansuriyaPosted Sep 11, 2015, 6:03 AM
Nice One
Rajeesh MenothPosted Sep 11, 2015, 5:38 AM
Superb Graphics...
Ankit BansalPosted Sep 11, 2015, 5:28 AM
nice one..
Mahesh ChandPosted Sep 11, 2015, 5:02 AM
LOL nice graphics :)