mvc 3 partials and usage - asp.net-mvc-3

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()

Related

Drupal 8 - Overwriting a specific view page

I have created a view with several pages. As it is displayed to me with the debug mode, I can also use the view:
views-view-fields--foobar.html.twig
Overwrite With me the whole then looks as follows:
views-view-fields--nd-portfolio-filter.html.twig
Now I would like to overwrite a certain page of my view. I can't find anything suitable in debug mode.
According to https://www.drupal.org/docs/8/theming/twig/twig-template-naming-conventions it should work according to the following pattern:
views-view-fields--foobar--page.html.twig
according to this logic it should look like this with me then as follows:
views-view-fields--nd-portfolio-filter--theaterfotos.html.twig
Unfortunately, that doesn't work. "theaterfotos" is the system name of the page of my view.
Do I have a thought error now? Would be grateful for any help.
Thnx Bavra
As of my understanding of your question you want to apply to the template on a specific page of view.
Your logic is right but I think your name was incorrect it should be in this format
[base template name]--[view machine name]--[view display id].html.twig
on your case, it should be like below because views machine name not using "-"(dash in between) on lowercase and underscores
views-view-fields--nd_portfolio_filter--theaterfotos.html.twig
you should try this and clear the cache of drupal. Hope this will helps you
Thanks

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.

Best way to group scripts or styles in the Head without a div?

Twofold question.
Using a web template that utilizes AJAX for loading new pages, rather than traditional point-the-browser-to-the-url style, how would one go about adding new script or style tags to the page head as necessary?
I think using jQuery $('head').append(script); works just fine, but (and here's the second half), if I wanted to group all of the scripts that were page-dependent away from those that are universal across the site - how would I do that?
Using a div sounds so enticing since I could print it at the initial page render and just call
$('head div.external').append(script), but still probably a bad idea inside the head.
Is there any other element or method I could use to group these? The goal being to easily remove all of them when the user navigates away from the current page. A smaller consideration is that Google Analytic instructs you to place it at the end of the head tag (I'll be honest, I don't know why being the last script matters), and I don't want my scripts to interfere. Do these even need to be in the head, could I place a div at the end of the body and use that?
Surely the easiest way to do this, if it is necessary, is with classes:
$(script).addClass('external').appendTo('head');
then later:
$('script.external').remove();
I'm honestly not sure what this would achieve, however.

Zend framework Nesting controllers

Zend framework Nesting controllers
I was wonder if it is possible to have nested controllers.
I have an application that has a page with left bar and right bar.
| --TAB----TAB----TAB--
MyGroups |
|
So I want to have one controller to be as a wrapper for entire page
then have myGroups controller for left bar, and for right side, there are many tabs that would show based on some selections.
So I want to have one controller for each tab.
This is a very big application and each of those tabs do lots of other things.
So I want have separate controller/model/view/layout for each tab and also for left side's myGroups.
What is the best way to approach this.
I appreciate if you give me some code structure too.
Thank you very much.
Alex
You could use the the Action view-helper in your layout for each or your left and right bars. But the downside to this is that you incur three full server calls (complete with bootstrap and dispatch cycle) to render a single page. I consider that to be a pretty significant downside, especially if each bar needs its own database connection.
An alternative approach is to use front-controller plugins for your left and right bars. Register them at bootstrap, give them a postDispatch() hook which accesses/generates whatever data they need and places that data into the layout/view. Then your layout renders the content without needing to know how it got there.
If you use the 'action view-helper' suggested by David, you could always ajax these in for better UX - therefore the user can read what has currently been loaded, while waiting for the rest of the page.

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

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.

Resources