Html.RenderAction cannot find my controller - asp.net-mvc-3

I have a razor masterpage (_Layout.cshtml) where I layout a 3 column website. In one of the side columns I want to display a "Login Control"
From my readings, I can use Html.RenderAction to call my LoginController and it will display the login view in the side column.
But, when I run it and point it to a Controller/View to fill the RenderBody(), the call to Html.RenderAction("Index", "LoginController") fails with this error.
"The controller for path '/[insert path to a Controller/View to fill the
RenderBody()]' was not found or does not implement IController. "
So, what am I doing wrong?
My code really is as simple as:
<div id="Navigation">#{ Html.RenderPartial("Test"); }</div>
<div id="Main">#RenderBody()</div>
<div id="Misc">#{ Html.RenderAction("Index", "LoginController");}</div>
And in my controllers folder, I have the controller for the RenderBody and the LoginController.

When specifying controller names by convention in MVC, you don't include the "Controller" part.
Html.RenderAction("Index", "LoginController")
wouldn't work unless you had a controller named "LoginControllerController"
try
<div id="Misc">#{ Html.RenderAction("Index", "Login");}</div>

Related

Include more controllers into a single page

I just started learning Laravel, and I want to include a second controller into my main layout.
The route is the default root directory: /
And the layout looks like this:
<div class="container">
#yield('content')
</div>
<div class="basket">
~basket comes here~
</div>
I want to show the user's basket, but I need DB queries for that, and I can't find a way to include an other controller, atleast not with routing.
I'm not really asking for code (Sadly i didn't find a better place for this question), probably I just need a designing tip, I really feel I'm trying to do it wrong, since I couldn't find any relevant/helpful information for this.
And I dont want to put the basket into every controller that uses my main layout.
Any kind of help would be apreciated, I'm really lost :)
You should use view composers. Open you AppServiceProvider and inside the boot() method add the following:
view()->composer('your.layout.name', function ($view) {
$basket = ...// Your basket query here
$view->with('basket', basket);
});
This basically says, when view with name your.layout.name is composed, add variable with name $basket.

EmberJS: How to handle actions from the View not the Route / Controller

Today I have come to a shocking discovery: actions referenced on a view are handled by their route, not by the view which referenced it. Ex:
<a href="#" {{action edit}}>Edit this</a>
The edit action must be defined in the Route, not in the View. When I was not using a Router before the View was the one responsible for handling such events and I was really happy about it.
Can anyone please:
explain to me why the Route must handle the event, and what are the benefits of this
tell me how can I give control back to the View in matters of handling such actions/events?
Set the target as view
<a href="#" {{action edit target="view"}}>Edit this</a>
If your action is in controller then use
<a href="#" {{action edit}}>Edit this</a>
Default target refers to the view's controller
I'd suggest you to go through this Reference: Ember Action Helper
I'd like to mention some key points as per the above reference
In a typical Ember.Router-backed Application where views are managed through use of the {{outlet}} helper, actions will be forwarded to the current controller.
If the action is not defined in the controller, then the current route is targeted.

Joomla include view in other view

I have problem with including Joomla views. I have many views in my extension and I want to include another one in my Dialog.
How can I do it?
In my first view I have this code:
<div id="modalDostawca" title="Dostawcy">
<div id="wewM">
//in here i want to include view data/tmpl/default.php
</div>
</div>
What kind of extension is your extension? A module? A component?
If it's a component, what you are trying to include is a template for a view, not a view! (the view is the one with view.html.php). Create a view + template for what you are trying to see. I don't think Joomla! can call multiple views at the same time. If you can reuse code inside models (if this is your concern).
You can also include files the normal way, with include(...).

Cannot submit form to controller zend framework

I create a from statically in HTML file in view project which is inside the module visit.
I want the controller to handle the request occur when submitting the form
<form action="addVisit" method="post">
<input type="text" name="number"/>
<input type="submit" name="save"/>
The structure of the project is
module visits
controller Visits and it has action addVisit
when submitting the form an error occur, the url becomes like this when submitting the form
http://localhost/zendApps/InspectionSys/public/visits/visits/VisitsController/addVisit
in the controller there is a function action
public function addVisitAction()
{
echo 'here';
}
what should I do ?
First you might reconsider camel caseing your actions addVisitAction() because if you do then you have to deal with view file names like add-visit.phtml I think it will affect urls as well, I find it simpler just to leave action names as lowercase addvisitAction(), this might be part of what's amiss.
Next identify your form actions as /module/controller/action (if you are not using modules you can omit that param), so your action should at least be /visits/visits/addvisit or /visits/visits/add-visit (not quite sure which will work properly) .
also when using html forms that were not generated by Zend_Form you can access the values using $this->getParams() or $this->getParam('paramName') instead of $this->getValues().

How do I separate the files for 'widgets' in codeigniter?

I have a basic cms that loads content into pages that have mustache tags to indicate where in the html code those contents will appear.
The contents are specified in a widget model which indicate which type of content is to be displayed, so for example, freetext with id. or another model and id. each one of those models will be displayed differently based on the model they are based on.
I can imagine this becoming and bit unwieldy, is there a way to have a separate folder to put those widgets in so that it doesn't clutter my main code.
Something like apotomo does on rails would be good, but for codeigniter.
A widget model? That is not so nice. Have you tried looking at PyroCMS?
https://github.com/pyrocms/pyrocms/blob/master/system/pyrocms/modules/widgets/libraries/Widgets.php
From the sound of it you may be more interested in our Plugins library (sounds like the same thing with a different name). It is set up with a MY_Parser and runs on top of Dan Horrigan's Simpletags implementation.
Either way this has all be done plenty. If you want some more specific tailored advice you might have to demo some of your code.
Create a folder inside application/views called widgets. Put your widgets inside that folder and create a separate file for each widget (d0h).
Next, you have 2 options (at least that i know of):
a.) Load the widgets into variables inside the controller, then pass them to the main/general view
$data['widget_twitter_feed'] = $this->load->view('widgets/twitter', '', false);
$data['widget_something'] = $this->load->view('widgets/something', '', false);
$this->load->view('my_main_view', $data);
b.) Load the widgets inside the main/general view itself
<html>
...
<div id="sidebar">
<?php $this->load->view('widgets/twitter'); ?>
</div>
...
<div id="footer">
<?php $this->load->view('widgets/something'); ?>
</div>
...
</html>

Resources