Geeks With Blogs

News
Anirudha gupta

In ASP.NET MVC We use Views and it’s help us to return a web-page back to browser. After Execution the Views we still have control on our response until Response.End() has called from ASP.NET itself.

In asp.net we use ViewBag and ViewData to pass the data. TempData is also can be used which is based on session and stay alive until second view has been returned.

For divining the complexity We use Partials to divide the whole page into many partials. For example.

https://gist.github.com/anirugu/8192708#file-multiple-models-through-a-partials

Using this way your partial have also data passed from their own PartialViewResult in Controller itself. You can call them something like this


@{
    Html.Action("Partial1","Home");  
}

Using given way we doesn’t need to care about passing viewdata to every partial. Remember that If controller is inherited from another class which have some ActionFilter attribute then they will also called in this implementation.

If your current action have data for the partial which you don’t want to retrieve again from database then you can also call it by pass then to partial directly from current View. For example look at this code.

@Html.Partial("~/Views/Home/Partial1.cshtml", new ViewDataDictionary { { "test", "test" } })

I pass the string “Test” in other case you call also pass the viewdata. for example ViewData.test .

 

Another way to divide the complexity is make a new custom class which contain all these information as property. For example https://gist.github.com/anirugu/8192888

In this post I shown you 2 way to use partials to divide complexity.

Thanks for read my post Smile

Posted on Tuesday, December 31, 2013 10:46 AM | Back to top


Comments on this post: How to divide complexity in asp.net mvc between views through Partial Views.

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Anirudha | Powered by: GeeksWithBlogs.net