partial-views

Rails calling action from view

帅比萌擦擦* 提交于 2019-12-05 18:47:01
Hopefully have a simple question here but I cannot for the life of me seem to find the answer. Just started working with RoR but came from ASP MVC before. I am having an issue rendering partial views whose local variables are not necessarily tied to the variables of the main view. For instance, with a blog I am trying to render a sidebar that will link to the archive. def sidebar @blog_posts = Blog.all(:select => "created_at") @post_months = @blog_posts.group_by { |m| m.created_at.beginning_of_month } end The partial view _sidebar is as follows: <div class="archives"> <h4>Blog Archive</h4> <%

RenderSection not working inside Partial View in ASP.NET MVC3

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 18:08:15
问题 In my ASP.NET MVC3 project I have a standard _Layout.cshtml generated by Visual Studio 2010 and after closing my <body> tag, I place a RenderSection : _Layout.cshtml: </body> <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script> @RenderSection("ScriptContent", required: false) </html> Then in my Index.cshtml View I have: @model MyApp.ViewModels.MyViewModel @{ Html.RenderPartial("MyPartial", Model); } If I place the @section ScriptContent in the Index

Add CSS references to page's <head> from a partial view

夙愿已清 提交于 2019-12-05 16:23:43
问题 Is there a way to add CSS references to a page from a partial view, and have them render in the page's <head> (as required by the HTML 4.01 spec)? 回答1: If you're using MVC3 & Razor, the best way to add per-page items to your section is to: 1) Call RenderSection() from within your layout page 2) Declare a corresponding section within your child pages: /Views/Shared/_Layout.cshtml: <head> <!-- ... Rest of your head section here ... -> @RenderSection("HeadArea") </head> /Views/Entries/Index

How should javascript in an ajax loaded partial view be handled?

耗尽温柔 提交于 2019-12-05 15:27:01
In ASP.NET MVC, what is the preferred pattern for running Javascript on a partial view that is loaded via Ajax? For example, suppose you need to wire up some click events in your partial view. Of course, putting something like this in the partial view would not work, because the document ready event won't fire after the partial view is Ajax loaded. <script type="text/javascript"> $(function() { $("a.foo").click(function() { foo(); return false; }); }); </script> I suppose something like this might work, but is it safe? <script type="text/javascript"> $("a.foo").click(function() { foo(); return

rails render_to_string giving errors with partial view

被刻印的时光 ゝ 提交于 2019-12-05 14:53:17
I am getting ActionView::MissingTemplate error when using render_to_string method with partial views, below the code bizz = render_to_string(:partial => "biz_new",:layout => false) Even though i have explicitly specified :layout => false , i am getting the MissingTemplate error always. But render_to_string with normal views works fine in the same project. what could be the reason? below the stack trace ActionView::MissingTemplate (Missing partial businesses/biz_new with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:text, " / "], :locale=>[:en, :en]} in view paths "/home/ramesh

ASP .NET MVC correct UserControl architecture

做~自己de王妃 提交于 2019-12-05 11:14:58
I'm trying to learn the new ASP .NET MVC framework and would like to know the best practice for using UserControls. I understand that you can render UserControl's as a partial and pass data to them from a controller. Ideally I would think that it makes sense not to have a code behind file as this creates a temptation to break the MVC rules. I'll give an example where I don't understand how UserControls fit into the pattern. I have a UserControl that shows the latest tags (much like on StackOverflow). Unlike StackOverflow I want to display this UserControl on all of my pages. If I have a

mvc partial view post

佐手、 提交于 2019-12-05 10:27:37
I have a company object which has a list of branch objects, my company view(residing in the company directory) has a strongly typed branch list view (residing in the branch directory)in it, each branch in the branch view has a delete button which I want to post to a delete action in the branch controller. at present the invoked delete action is the one in the company controller (there is a delete action in both company and branch) I believe I understand the reason it is doing what it is, however what is the best practice in this situation.... should the branch list partial view reside in the

Dynamic partial view + jquery form hijack + client validation = not working

让人想犯罪 __ 提交于 2019-12-05 08:41:35
I'm using MVC 3 with unobtrusive javascript for client validation. I have a table with rows which are clickable. When clicked I want to bring up a dynamically loaded partial view. This is the code for this: function GetStuff(id) { $.ajax( { url: "Edit/" + id, success: function (result) { $("#DivTest").html(result); } }); } This far everything works. The problem is when I'm trying to save something in the partial using jquery. The form is hijacked, like this: $(function () { $.post($(this).attr("action"), $(this).serialize(), function (data) { alert("test"); }); e.preventDefault(); }); This all

Render partial form in jQuery dialog

不想你离开。 提交于 2019-12-05 08:07:19
问题 Most of you probaly know Nerddinner.com, and my page is much like that, so let's imagine doing this to Nerddinner. When editing a dinner, you'll be redirected to Dinners/Edit.aspx, and presented of the partial view DinnerForm.ascx of type DinnerFormViewModel. What if you wan't this DinnerForm presented in a jQuery UI Dialog? I'm thinking: On the page where you choose to edit the dinner, you'll have a div containing the partial view DinnerForm: <div id="editDinnerForm"> <% Html.RenderPartial(

ASP.NET MVC 3 Partial View dynamically rendered and linked from dynamic list in view

99封情书 提交于 2019-12-05 07:00:15
问题 In my MVC 3 application, I will have a view that will contain a partial view. The view itself will have a list of dynamically generated links. The link has to cause the partial view to render detailed information for that linked item. Would I use Ajax for this? If so, since I haven't worked with Ajax before, is there any documentation for using it in a MVC 3 app? Also when the view is first loaded, the partial view will either not be loaded or ideally show another separate partial view. Any