Monday, 20 April 2015

Difference between Asp.Net MVC and Asp.Net WebForm


Difference between html.partial and html.renderpartial

Both of these helper methods are used for rendering partial views.

Main Differences:
 
1. The return type of the  "RenderPartial" is void, where as  "Partial"  returns "MvcHtmlString"

 
2. Syntax  in Razor views


 { Html.RenderPartial("PartialViewName");  }
@Html.Partial("PartialViewName")

3. Syntax in webform views


 <% Html.RenderPartial("PartialViewName"); %>
<%: Html.Partial("PartialViewName") %>


The main difference is that "RenderPartial()" returns void and the output will be written directly to the output stream, where as the "Partial()" method returns MvcHtmlString, which can be assigned to a variable and manipulate it if required. So, when there is a need to assign the output to a variable for manipulating it, then use Partial(), else useRenderPartial().

RenderPartial() is better for performance over Partial(). 
 

Partial view in Asp.net MVC?

View :

 Url is nothing but Controller name, Action name along with parameters.

 function (Name, Id) {

            var _settings = {
                url: '/Abc/ViewData?name=' + Name+ '&id=' + Id+ '',
                cache: false,
                type: 'GET',
                beforeSend: function () {
                    $self._helper_.__showAjaxLoading();
                },
                success: function (data) {
                    $("#divConceptAndProgramQuickView").html(data);
                },
                error: function (jqXHR, textStatus) {
                    console.log("Something went wrong: " + textStatus);
                },
                complete: function () {
                    $self._helper_.__hideAjaxLoading();
                }
            };
            $.ajax(_settings);
        }



Controller :

 public class AbcController: Controller
  {
  public PartialViewResult ViewData(string name, int id)
    {
      List<SearchField> searchFields = new List<SearchField>() {

                   new SearchField() { Name=SearchFieldNames.ConceptOrProgram.ToString(), Value=conceptOrProgram} ,
                   
                   new SearchField() { Name=SearchFieldNames.ConceptOrProgramId.ToString(), Value=conceptOrProgramId.ToString()}
                
                          
            };
      List<ConceptsAndProgramsQuickView> conceptAndProgramsQuickViewData = IDVBManager.GetConceptsAndProgramsQuickViewData(searchFields);


      return PartialView("partialViewName", conceptAndProgramsQuickViewData );
    }
}