Asp.Net MVC 3 - #Html.Action won't render/return any HTML - asp.net-mvc-3

I've been moving a fairly new project from ViewPages to Razor today, and all seems to be going well. Except I'm trying to use Html.Action to render a user control and it won't render anything.
So I have a Shared/_Layout.cshtml file which is referenced in Home/Index.cshtml
Index.cshtml has the following:
<article>
#Html.Action("LatestBlogsMainPanelWidget", "Blogs")
...
</article>
I've put traps in the BlogsController, so I know that's being requested. I also know that a model is being returned, that the LatestBlogsMainPanelWidget is being found by the view engine, and even some dummy Razor syntax code is being run:
#{
var s = "hello";
}
but the plain html in this file isn't making it to the browser. I've tried other (previously working) partials too and they won't appear either (view source on the page confirms it's not there).
I've also tried substituting for
#{ Html.RenderAction(...); } without success. HTML either side of the #Html.Action is appearing, so I know Index.cshtml is displaying properly.
Even more strangely the _Layout file also has Html.Action commands and they do appear fine.
I'm really not sure what else to check, or how to confirm that the pipeline is getting the HTML. Can anyone help at all?
Thanks!

Put a Layout = null on the partial view and it will work fine.

Try this:
#{Html.RenderAction("LatestBlogsMainPanelWidget", "Blogs");}

The brain is a funny thing, and despite spending several hours on this yesterday, it took my dog waking me up in the middle of the night for a wee for my subconscious to stumble upon the answer.
If this had anyone else stumped, I'm not surprised. I hadn't mentioned because it hadn't dawned on me that I was using a partial-level caching system similar to one designed by Steve Sanderson. It suddenly struck me that this could be the cause, since to the best of my knowledge Razor pages go through far less pipeline processing than WebForm pages. The caching filter is probably not doing what it needs to do, or at the right time.
I've confirmed that commenting out the OutputCache filter on the Actions in question has fixed the problem.
I've no idea if this issue is true of the page-level caching as it's not something I find useful.

While searching solutions for this issue, I have find out three measure issues for not proper rendering of Html.Action and Html.RenderAction. Please verify have you done below things properly or not.
In your PartialView or View you have defined #{Layout = null;}.
Use return PartialView instead of View .
Decorate your action with [ChildActionOnly] attributes.
I hope by applying above all steps you can solve your issues.

Related

CKEditor with HTML content stores, displays but cannot display for edit

I have used CKEditor for a few years without really understanding it. I now want to use it to display text which will include HTML, CSS, JavaScript and PHP example code. None of that needs to execute it is just to show the code to others.
Currently I used the textarea replace method to edit content and I need to carry on that way. When I add the content first time it is sanitised (mysqli_real_escape_string) and stored in a MySQL database correctly. It also then displays correctly with the CKEditor markup working as markup and the HTML/PHP showing as a code example. However, when I edit the content a second time the HTML examples become "real" HTML and are no longer visible as examples.
For example this:
<?php echo "hello"; ?>
<p>Hello</p>
is correctly (?) stored as:
<p><?php echo "me"; ?></p>
<p><p>Hello</p></p>
and displays on the page as shown in the first code snippet (which is what I want). When I then hit edit again the code examples vanish into the background as real HTML (part of the page). If I put the code examples in as code snippets (which I would rather not have to do because of the intended users) the result in the editor (second edit) looks like this:
<!--?php echo "me"; ?-->
Hello
I am sure i am missing a basic understanding of what is going on behind the scenes but can anyone explain how to allow users to type in text which includes HTML, CSS, JavaScript, PHP and MySQL code examples which must then appear as examples and not markup (and be editable as examples).
I have played with config.entities and config.protectedSource after some research but they do not seem to be relevant (or to work). Weirdly a couple of times it seemed to work fine and I thought I had cracked it but then stopped with no further changes to the config. That means I now have less idea what I am doing than when I started!
You don't mention which version you are using, but if it's relatively new (4.4+) you can use the Code Snippets plugin that was designed exactly for this. See the demo at http://ckeditor.com/demo#widgets. It might help with the encoding issues too. There's docs on it too.
Th help with the current encoding issue, it would help a LOT if you showed us how you output the data and load it into CKEditor. For example "When I then hit edit again" doesn't really describe anything without context. For example, do you use setData() with AJAX? Do you use an inline editor? Code examples would be the best.

Laravel blade debug view name on error

when there is some error in view, L4 shows a nice trace, but cached filename:
open: /var/www/webpage/app/storage/views/1154ef6ad153694fd0dbc90f28999013
howto during view-rendering-to-cache save view's path/name (in a comment or something)?
Or better yet - to show it in the debug-error-page (its called whoops or something?)
Thanks ;)
I don't know how to de encrypt view names , but one method i do is to
{{dd('will you reach here ')}}
Trying to move this line from view to another to watch where php render reach .
I know it is not the right way nor the professional one , but it may help in some cases .
This is not exactly a problema, this is a compiled version of your view.
Laravel Blade System will compile all your views and subviews into a single file and, if you didn't change anything on them it will always try to use the compiled version, to speed up your system.
Sometimes is hard to know wich one of our views is related to that error. Using Sublime text, what I do is to hit CTRL-P (windows) and paste the number of the compiled view (1154ef6ad153694fd0dbc90f28999013) and it will bring it to me right away.
Of course, you won't do any changes on it. This is just way to find the view you have problems in, so you can then find the real file and fix it. If you know wich file is the problematic one, you don't have to do this, go directly to your file.
One way to tackle this problem is add a html comments (not blade ones as they will not be rendered in compiled view) in sections which get echoed.
#section('content)
<!-- FILE: app/views/main/index.blade.php -->
<Your Content Goes Here>
#stop
This html comment will get rendered in the compiled source of the view. Of course you will have to inspect the compiled view first to identify which view is the problematic one. But in my experience, this method work almost all the time.
I created a helper that checks to see if you are working locally or in development mode, It then outputs an HTML comment.
{{ printViewComment('mockup/reports#content') }}
<!-- Template: mockup/reports#content -->
I chose to name the comments like this path.file_name#yeild_name but I only wish this was an automated featured.
I found my answer after looking into source,
when on the Whoops! page, just look for render in the sidebar, there will be the name of the view file...

Am I misusing Ruby on Rails Layouts

EDIT:
Okay, so using cells I have got it running, indeed the rb file created by the cells scripted needed:
helper ApplicationHelper
this got past the error in the comments below, but now inside my application helper, i have a method:
def hr_user_past
#current_year = current_year
#hr_user_past ||= Employee.where("username=? and year < ?", session[:hr_user].username, #current_year).order("Year DESC") if session[:hr_user]
#past_times = #current_year - 2011
#blart = 'test'
end
And alas, this now cannot find current_year which is a def method in my application_controller.rb, so I think my flow is all messed up and not sure what I need to have where for a good solid "include".
Def of the current_year from application controller
class ApplicationController < Actioncontroller::Base
helper_method :current_year
...
...
def current_year
OpenPeriod.maximum :year
end
end
I also am worried all this work still wont solve the issue I am having with the twitter bootstrap modal dialog being called from a layout and not fadeing in all the way with data (minute i put the same code in a view, it works right)... but one issue at a time i guess...
END EDIT
Trying to have an objective question here though. Some background:
I have a navigation layout that has this nice login, home button and a few others on it. It works fine, lately the customer wanted some more functionality added to this namely a smart button that drops down dynamically with data filled out (stuff from years past from old forms we use).
So the app used a twitter bootstrap modal elsewhere. I just posted this question here:
twitter bootstrap modal does not work in rails3 layout?
Where I am having an issue with this modal working correctly from the layout. Then I got to thinking, this modal that drops down has some good amount of data usually from a specific controller, but they want to see this data at any moment. Is the layout way of doing this not the way, should I build an application helper .rb code to fill out a partial and include that partial on every page in the app? ( seeems like it should fix my modal displaying oddly, like constantly faded issue). I think my green-ness to ruby on rails is at fault here. I know its awesome and there is a lot to it and this is the first project I have done in it. So I am not sure what the correct solution is here, and I think its a vocabulary issue. Like what am i looking for?
Form helpers
Templates
Partials
etc etc... what is the best fit here? I realize in coding there is a lot of ways to skin a cat but I am not sure where to ask. Rereading this is getting subjective. Basically
I have a home controller that sets up things on a home page, turns out this data needs to be seen by the user at any given moment from any page in the app. Tried to move it to our navigation layout, its not going well. Is this the right approach or is there a better one?
One approach would be to use Cells. Essentially, a cell is a miniature controller that takes care of fetching data and rendering a view. It's not quite a full-blown view, it's a component which, similar to a partial, may be included into other views of your application - or even the layout, which is useful when you have something that appears on every page.
A classic example (which they implement on their homepage) is that of a shopping cart - it appears throughout your app but it needs to have some data set; turning it into a cell extracts both the querying and the rendering into a nicely-separated MVC unit.

mvc 3 partials and usage

We meet again stackpeople!
I have been using the last 2 days trying to find the answer I need.I can't seem to find a straight forward answer on WHEN to use partialviews I know you can use em for like login component and all the other fancy stuff
.
But what about the navigation bar ? I tried making the navigationbar with partials and Ajax.htmlactionlink but then the problem comes, I know since its just a partial my URL won't get rewritten which means on f5 it will always update my home/index since no URL was given . Is this cus I can't make my navi like that or just because im plain stupid ?:)
Partials should be used to avoid code duplication. Create one if you find yourself writing the same view code over and over again.
A navigation bar sounds more like something that should be in the layout. You can use Sections in Razor and ContentPlaceHolder for the webforms view engine if you want to let pages customize the layout.
I don't think the partials have anything to do with it(it shouldn't, partials are just a way to split up source files so you can reuse them later).
I'm guessing the problem lies in the use of AjaxhtmlActionlinks, why would you want to do an Ajax call to redirect the user?
Try using the normal #Html.ActionLink()

Adding pager to custom collection block

Sorry for the redundancy of this question, but none of the example and solutions have worked for me. I have a custom module that extends Mage_Catalog_Block_Product_List. The only function in it is _getProductCollection which sets the product collection based on which attribute you want to filter on. It's pretty simple and there are no layout updates involved. I put the block on the page by putting the following into the Content section of a CMS page:
{{block type="vps_featured/list" name="vps_featured_list" attribute_name="best_sellers" template="catalog/product/sale_list.phtml"}}
Since it extends Mage_Catalog_Block_Product_List, I get all the bells and whistles for a product list page, including the toolbar. However, the pager isn't there. I've tried a number of different suggestions but none have helped.
I looked in Toolbar.php in the core code and found where it calls getPagerHtml. I put some debug statements in there and determined that it calls this function when putting my custom block on the page but $this->getChild('product_list_toolbar_pager') is not returning the block, presumably because it isn't there. I tried adding the block using a layout update XML file and adding the <frontend><layout><updates>... tags to my config, but this didn't seem to do anything.
I have Alan Storm's CommerceBug extension, so I pulled that up and exported the layout XML for the page. It doesn't contain any toolbar block at all, despite the fact that the toolbar is on the page and only the pager isn't working. If I do the same thing on a category landing page, it shows the toolbar block in the layout xml. So I've clearly missed something here, but I'm at a loss as to what. I hope someone can help :)
Brian
As it turns out, the solution found HERE works great! You have to add the block using the Layout Update XML rather than adding it in the content section. I still don't quite understand why, but it works.
There already was question about Getting pager to show on magento list

Resources