Friday, 24 July 2015

Rendering Helpers in MVC

MVC provides many Rendering helpers and you can use it based on your need ;
Please see on below links for more details about it.


1. @HTML.Action and @HTML.ActionLink

2. URL Helpers

3. @HTML.Partial and @HTML.RenderPartial

4. @HTML.Action and @HTML.RenderAction in MVC

@HTML.Action and @HTML.RenderAction in MVC

Action and renderAction are similar to Partial & RenderPartial helpers.
Partial helps to view render a portion of view model using view markup in separate file.

Action execute a separate controller action and display the result. Action offer more flexible and reuse because the controller action can build a different model and make use of a separate controller context.

Difference in action and renderaction is the render action writes directly to the response.

URL Helper in MVC

The URL Helper is Similar to HTML Action Link & Route Link Helpers. http://www.getmscode.com/2015/07/htmlactionlink-mvc.html

But instead of returning HTML, they build URLs & return URLs as string.

Three Helpers for URL.
Ø  Content
Ø  Action
Ø  Route URL


Action URL is same link Action link, But doesn’t return an anchor Tag.
@URL.Action(“Browse”,”Store”, new { ID = 100}, null)

HTML.ActionLink MVC

The actionlink method renders a hyperlink (anchor tag) to another controller action.

e.g When linking to action in the same controller used to render the currentview, you can simply specify the action name;

@html.ActionLink(“Link Text”,”Action”);

This produces the flowing markup.

<a href=“/home/anotheraction”>LinkText</a>

You can specify the action
@Html.ActionLink(“Link Text”, “Index”,”Open”);


Sunday, 19 July 2015

Difference between @Html.Partial and @Html.RenderPartial

Generally we are getting confuse to use @Html.Partial and @Html.RenderPartial.

You can see below for Difference between @Html.Partial and  @Html.RenderPartial it help you to use it

1.       Return Type :  Partial Return Type is MVCHtml String; whereas RenderPartial  return type is void.

2.       Implementing  : Calling of partial Need to  call as:
@HTML.Partial(“PartialViewName”);
Render Partail Will call as;
{HTML.RenderPartial(“PartialViewName”)}
We enclose it like this because return type is Void;