partial-views

rails access view name inside partial

為{幸葍}努か 提交于 2019-12-21 07:55:59
问题 I have a partial that I am using in different pages. I want to conditionally hide a certain div inside the partial based on the view that is rendering it. I was thinking about creating a page specific javascript file that would look up the div and and hide it. But, if there was a way to retrieve the view name / page name inside the partial it would be central to the partial and would not necessitate loading the same javascript file in multiple pages. Does anybody know a way to do this inside

Update A Partial View From Another Partial View - ASP.NET MVC2

痞子三分冷 提交于 2019-12-21 04:55:23
问题 I want to have two partial views , one for SEARCH and one for SEARCHRESULTS . I want to update SEARCHRESULTS when the "Search" Button is clicked on the SEARCH partial view form. SEARCHRESULTS needs to have the form data fed to it from the SEARCH partial view. I'm not totally sure how to go about this. Can I update the SEARCHRESULTS partial view from my SEARCH partial view's Controller action? 回答1: General Discussion In the MVC design pattern views are unaware of each other. They may be bound

asp.net mvc - pass partial data model to partial view

谁说我不能喝 提交于 2019-12-20 23:11:52
问题 I wish to build a partial view that gets a model column and print it. Something like that: At the view: @model IEnumerable<products_comparison.Models.Product> @{ ViewBag.Title = "Index"; var Brand = (from r in Model select r.Brand).Distinct(); } <h2> Index</h2> @Html.RenderPartial("_DisplayAttribute",Brand) And at the partial view: <table> <tr> <th> Brand </th> </tr> @foreach (var row in Model) { <tr> <td> @Html.DisplayFor(r => row) </td> </tr> } </table> There are a few problems I run into:

What does the j function in Rails do?

时间秒杀一切 提交于 2019-12-20 17:35:04
问题 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 found some articles that say it converts the string to something JavaScript will accept, but what does that mean? 回答1: escape_javascript(javascript) Escapes carriage returns and single and double quotes for JavaScript segments. Also available through

Rails remote delete and update view through Ajax

落爺英雄遲暮 提交于 2019-12-20 14:06:12
问题 In the past, whenever I wanted to update a part of my view through Ajax, I've done the following: create a partial out of the part I want to update and give it a unique ID, say #tracks create a special action in the controller for that Ajax call, say remove_track that updates all the values, etc. and add format.js create a new JS file with the same name as the action so Rails calls it automatically remove_track.js.erb which contains something like: $('#tracks').html("<%=j render 'cds/show

Rails remote delete and update view through Ajax

偶尔善良 提交于 2019-12-20 14:06:06
问题 In the past, whenever I wanted to update a part of my view through Ajax, I've done the following: create a partial out of the part I want to update and give it a unique ID, say #tracks create a special action in the controller for that Ajax call, say remove_track that updates all the values, etc. and add format.js create a new JS file with the same name as the action so Rails calls it automatically remove_track.js.erb which contains something like: $('#tracks').html("<%=j render 'cds/show

ASP.NET MVC3 Partial View naming convention

♀尐吖头ヾ 提交于 2019-12-20 10:59:16
问题 I'm new to the MVC development so please bear with me. Is it really necessary to name my partial view like _Action.cshtml (with the _ underscore) to comply with the naming convention? Here's my problem I have a controller (StudentController) and an action (List) that has a partial view file named "List.cshtml", and have @{ Html.RenderAction("List", "Student"); } to display this inside my HomeController - Index view as partial view which works. But if I name my partial view to _List.cshtml of

ASP.NET MVC3 Partial View naming convention

走远了吗. 提交于 2019-12-20 10:59:05
问题 I'm new to the MVC development so please bear with me. Is it really necessary to name my partial view like _Action.cshtml (with the _ underscore) to comply with the naming convention? Here's my problem I have a controller (StudentController) and an action (List) that has a partial view file named "List.cshtml", and have @{ Html.RenderAction("List", "Student"); } to display this inside my HomeController - Index view as partial view which works. But if I name my partial view to _List.cshtml of

What is the correct place for Partial Views in ASP.NET MVC?

霸气de小男生 提交于 2019-12-20 10:58:54
问题 Would someone confirm the best place for a partial view in ASP.NET MVC? My thinkings are if it's a global view that's going to be used in many places then SHARED. If it's part of a view that's been wrapped up into a partial view to make code reading easier, then it should go into the Views/Controller directory Am I correct or am I missing something? 回答1: I believe you are correct. Here is an example of something I do, general navigation partial views in my Shared directory. and then a partial

Rendering Partials From One Controller’s View to Another Controller’s View in Rails

北慕城南 提交于 2019-12-20 08:50:47
问题 I have a view for a controller called "show". Inside that view, i want to render the contents of another controller's view - and obviously, the logic for the form on that view to talk to the controller it belongs too. How do I do this? I am fairly new to rails and I'm not 100% confident with the framework yet. You could almost consider them "widgets" on the view. I know you can render actions from the same controller on the view by using: render :action => "show_home_page", :layout=> false