1.

What is PartialView

Answer»

when we want a certain code to be used at some other view, we use a partial view. In simple words we can SAY that  it is a child view which can be used in some other views, it prevents the duplicate of code since it used the same partial view at some other places

When we want a partial view to be used on multiple controllers then we need to create a shared folder in the solution, OTHERWISE, if it using in a single controller then it doesn`t need it. Using Partial() or RenderPartial() or RenderAction() helper method .we can render the partial view content in its parent view

@Html.Partial() helper method renders the specified partial view. It returns HTML STRING so we have a chance of MODIFYING the HTML before rendering.

The different types of overloads used in partial views are:

  1. MvcHtmlString Html.Partial(string partialViewName)
  2. MvcHtmlString Html.Partial(string partialViewName,object model)
  3. MvcHtmlString Html.Partial(string partialViewName, ViewDataDictionary VIEWDATA)
  4. MvcHtmlString Html.Partial(string partialViewName,object model, ViewDataDictionary viewData)
  • MvcHtmlString Html.Partial(string partialViewName): it Renders the given partial view content in the referred view.
  • MvcHtmlString Html.Partial(string partialViewName, object model): in this, the modal passes its parameter into the partial view and render the view which is referred to it.
  • MvcHtmlString Html.Partial(string partialViewName, ViewDataDictionary viewData): it passes the view data dictionary to the partial view and render the partial view content in the preferred view.
  • MvcHtmlString Html.Partial(string partialViewName, object model, ViewDataDictionary viewData): when we want to pass the model object and view data dictionary to the partial view, and render the partial view content in the referred view.


Discussion

No Comment Found