Questions tagged [partial-views]

User control in Asp.Net Web forms that is used for code re-usability. Partial views helps us to reduce code duplication . Reusable views like as Header and Footer views .

Partial view is like a regular view with a file extension .cshtml. We can use partial views in a situation where we need a header, footer reused for an MVC web application. We can say that it’s like a user control concept in ASP.NET.

2715 questions
1079
votes
13 answers

Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

In ASP.NET MVC, what is the difference between: Html.Partial and Html.RenderPartial Html.Action and Html.RenderAction
Ghooti Farangi
  • 19,926
  • 15
  • 46
  • 61
414
votes
22 answers

How to dynamically change header based on AngularJS partial view?

I am using ng-view to include AngularJS partial views, and I want to update the page title and h1 header tags based on the included view. These are out of scope of the partial view controllers though, and so I can't figure out how to bind them to…
Michael Low
  • 24,276
  • 16
  • 82
  • 119
379
votes
23 answers

Injecting content into specific sections from a partial view ASP.NET MVC 3 with Razor View Engine

I have this section defined in my _Layout.cshtml @RenderSection("Scripts", false) I can easily use it from a view: @section Scripts { @*Stuff comes here*@ } What I'm struggling with is how to get some content injected inside this section…
tugberk
  • 57,477
  • 67
  • 243
  • 335
182
votes
4 answers

How can I pass parameters to a partial view in mvc 4

I have a link like this: Profile and when I click on this it will call this partial page: @{ switch ((string)ViewBag.Details) { case "Profile": { …
neel
  • 5,123
  • 12
  • 47
  • 67
98
votes
5 answers

Rails: confused about syntax for passing locals to partials

Understanding Rails "magic" with regards to rendering partials (and passing locals into them). Why does this work: <%= render "rabbits/form" %> And this work: <%= render "rabbits/form", :parent => @warren, :flash => flash %> but this does not…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
84
votes
11 answers

Getting index value on razor foreach

I'm iterating a List in a razor foreach loop in my view which renders a partial. In the partial I'm rendering a single record for which I want to have 4 in a row in my view. I have a css class for the two end columns so need to determine in the…
lloydphillips
  • 2,775
  • 2
  • 33
  • 58
82
votes
7 answers

How to include a partial view inside a webform

Some site I'm programming is using both ASP.NET MVC and WebForms. I have a partial view and I want to include this inside a webform. The partial view has some code that has to be processed in the server, so using Response.WriteFile don't work. It…
eKek0
  • 23,005
  • 25
  • 91
  • 119
77
votes
2 answers

Using partial views in ASP.net MVC 4

I have recently started playing around with ASP.net MVC (4), but I can't wrap my head around this one issue I'm having. I'm sure it's easy when you know it. I'm essentially trying to do the the following in my Index view: List the current items in…
Espen S.
  • 877
  • 1
  • 8
  • 11
77
votes
5 answers

Is it OK to put JavaScript in Partial Views

I’m working on the web app where the main page contains two parts: the constant block which is always visible and the info-block made up by one of 3 partial views. Each of the partial views appears as a result of AJAX request and is loaded just once…
Tomy
  • 823
  • 1
  • 7
  • 11
72
votes
10 answers

Include JavaScript file in partial views

I am wondering what the best practice is for including javascript files inside partial views. Once rendered this will end up as a js include tag in the middle of my page's html. From my point of view this isn't a nice way of doing this. They belong…
Peter
  • 14,221
  • 15
  • 70
  • 110
65
votes
5 answers

Render Partial View from other controller

Is there a way to render inside my view of controller A a partial view from other controller B? Edit: I wrote a partial view that is good for only two controllers and I don't want to copy it to their both Views folder. I want The partial view to…
gdoron
  • 147,333
  • 58
  • 291
  • 367
64
votes
6 answers

Create controller for partial view in ASP.NET MVC

How can I create an individual controller and model for a partial view? I want to be able to place this partial view any where on the site so it needs it's own controller. I am current rendering the partial as so @Html.Partial("_Testimonials")
brenjt
  • 15,997
  • 13
  • 77
  • 118
61
votes
10 answers

How to Render Partial View into a String

I have the following code: public ActionResult SomeAction() { return new JsonpResult { Data = new { Widget = "some partial html for the widget" } }; } I'd like to modify it so that I could have public ActionResult…
DaveDev
  • 41,155
  • 72
  • 223
  • 385
56
votes
2 answers

What does the j function in Rails do?

I just came across a blog that mentions a j function in Rails. They were using it to do ajax style page updates. $('#cart').html("<%=j render @cart %>"); I get they are using partials to render the cart partial, but whats the point of j? I've…
Tyler DeWitt
  • 23,366
  • 38
  • 119
  • 196
50
votes
5 answers

Node.js + Express + Handlebars.js + partial views

I am trying to make a simple HelloWorld project with Node.js|Express using Handlebars.js as a server template engine. The problem is that I couldn't find any examples of using such chain, especially with multiple view. For example I would like to…
Artem Yarulin
  • 509
  • 1
  • 7
  • 12
1
2 3
99 100