partial-views

Yii loading jquery multiple times

放肆的年华 提交于 2020-01-06 04:12:13
问题 I currently have a page which renders 6 partial views. The problem that I am now facing is that, because I need to set processOutput to TRUE, jquery is loaded multiple times. I tried to resolve this by adding <?php Yii::app()->clientscript->scriptMap['jquery.min.js'] = FALSE; ?> <?php Yii::app()->clientscript->scriptMap['jquery.js'] = FALSE; ?> To my partial view. The problem is, that by doing so, jquery doesn't load AT all. Anyway to resolve this so it will only load once? 回答1: Change your

Pass anonymous type as model in MVC 3 Partial View

耗尽温柔 提交于 2020-01-06 02:53:09
问题 I am refactoring an MVC 3 application, and moved a set of similar items into a partial view so I can keep that template DRY. Since the pieces don't all have the exact same properties, I am creating anonymous types like this: var model1 = new { Description = "description 1", Message = "message 1" } and passing them to the partial view like so: @Html.Partial("_Partial", model1) The partial view is then attempting to render certain blocks based on existence of a specific property, i.e. @if

How to pass data to a PartialView in my layout?

主宰稳场 提交于 2020-01-05 08:08:31
问题 I have a _layout.cshtml containing this row: @{Html.RenderPartial("Menu");} Now I want to pass in a model into this RenderPartial-function. This model can be read from my repository. How and where(in code) can this be done? Thanks! 回答1: RenderPartial has an overload that can take an object to send it to the partial view. Don't forget to define your @model at the top of your partialview to work with the right object type. @Html.RenderPartial("ViewName",object) Extra info: MSDN Edit after

What does “render @collection” do?

早过忘川 提交于 2020-01-04 16:59:15
问题 I'm trying to learn Rails better by looking at example applications, and while looking at this line of the source of railscasts.com, I noticed it does this: <div class="episodes"> <%= render @episodes %> </div> What exactly is going on here? Why isn't this documented on the render function? Or is it? 回答1: This is shorthand for render :partial => "episode", :collection => @episodes The form above is documented in the Rails API docs under render (ActionController::Base) . The shorthand form is

What does “render @collection” do?

孤街醉人 提交于 2020-01-04 16:58:17
问题 I'm trying to learn Rails better by looking at example applications, and while looking at this line of the source of railscasts.com, I noticed it does this: <div class="episodes"> <%= render @episodes %> </div> What exactly is going on here? Why isn't this documented on the render function? Or is it? 回答1: This is shorthand for render :partial => "episode", :collection => @episodes The form above is documented in the Rails API docs under render (ActionController::Base) . The shorthand form is

Refreshing parent view when a partial view's form is submitted

夙愿已清 提交于 2020-01-03 04:40:10
问题 I'm looking into using partial views in MVC3 using Razor, and I get my partial view to render and it works fine. What I'd like to do, though, is refresh the parent view when the partial view is submitted. Code in my parent view to render partial view <div id="mydiv"> @{ Html.RenderAction("Add", "Request"); } </div> Action for parent view is simple, public ActionResult Index() { List<obj> reqs = //some query return View(reqs); } In my partial view's get action I have: public ActionResult Add()

ASP.NET call a controller method from the master page?

你说的曾经没有我的故事 提交于 2020-01-02 09:55:44
问题 In ASP.NET MVC2 how do you call a controller method from the master page? Say for example I wanted to include some overview data in the master: +--------------------------------------+ | Logo Welcome xyz| +--------------------------------------+ | total sales this month $999 | +--------------------------------------+ | Home | Sales | Import | Export (menu)| +--------------------------------------+ And I have inside the Sales controller this method: public ActionResult TotalSalesThisMonth() {

Problem with different model type in partial view

泪湿孤枕 提交于 2020-01-02 05:01:19
问题 I have one (razor) page that contain 5 different partial views. Each partial view is responsible for some data from database. In that master page I use one model object but for partial views I use different model objects. The problem is that when I set model object in partial view my application breaks with following error: The model item passed into the dictionary is of type 'MyProject.WebUI.Models.BigPageViewModel', but this dictionary requires a model item of type 'MyProject.WebUI.Models

How to test PARTIAL view was rendered in C# ASP .NET MVC

一曲冷凌霜 提交于 2020-01-02 04:54:06
问题 I have a view and it has partial view rendering inside: <div class="partialViewDiv"> @Html.RenderPartial("partial", Model.SomeModelProperty); </div> And a controller, which returns this view public ActionResult Action() { ... var model = new SomeModel(){SomeModelProperty = "SomeValue"} return View("view", model); } How to test view was rendered i know: [TestMethod] public void TestView() { ... var result = controller.Action(); // Assert result.AssertViewRendered().ForView("view").WithViewData

How can I reload a div with a PartialView in ASP.NET MVC using jQuery?

送分小仙女□ 提交于 2020-01-01 06:55:11
问题 I have a div with a partial inside somewhere on the page. I have a event on a button. How could I write a Javascript that takes the div and reloads it and also reloads the partial view. I have this in another view. But I can't do it like this now. But I need the same thing to happen only execute by a jQuery not directly in the page. Can i run maybe simular ajax code in the jQuery script because its javascript too isn't it?. <% using (Ajax.BeginForm("EditFeiertag", new AjaxOptions {