MvcSiteMapProvider preservedRouteParameters Usage - mvcsitemapprovider

I have a route defined on my controller action
[Route("xxx/{xxxId:int}/yyy/{yyyId:int}/Details/{editable:bool}")]
I have used 'preservedRouteParameters' and managed get the breadcrumb showing
My mvcSiteMapNode is like this:
mvcSiteMapNode title="TheTitle" controller="yyy" action="Details" preservedRouteParameters="xxxId, yyyId, editable"
I'd like to have the breadcrumb url contain the Id for the previous stage. i.e. xxxId.
Can anyone help with how to achieve this?
[edit]
Having played with it a little more it seems that the problem I have is that my 'id' is not named consistently.
In the parent I have 'id' and the sub page I have 'xxxId'
Changing them both to be just 'id' seems to have worked.

Related

MVC5 Getting a button to call an action method in Controller

As the heading states when I click a button on my main view I need it to call a method in my controller for that view. Ive been trying for hours and Ive changed the specific lines of code many times but all variations seem to give the same errors so im just showing the simplest versions to get my point across. Everytime I try something I get a 404 error that the path is not found. So im assuming something is wrong with the code in my view. Im not using JQuery or any javascipt
The line of code in my index view:
#Html.ActionLink("Button4Pressed", "Button4Pressed", "HomeController");
I know this wont work for getting methods but it works for changing pages so I thought I would start there. Im not sure if I should be doing it as a href or button.
my method in my HomeController:
[HttpPost]
public ActionResult Button4Pressed()
{
state = "year";
MyChart();
return View();
}
heres my Solution Explorer
Im pretty new to MVC and propably doing some pretty stupid stuff so any help is appreciated thanks.
You have two options:
Option A
Remove the [HttpPost] attribute from your controller method and you will be able to create normal links to it, i.e. with #Html.ActionLink()
Option B
Keep the [HttpPost] attribute and use a form or ajax to send the request as a HTTP Post request, i.e.
<form id="Button4Pressed" action="#Url.Action("Button4Pressed", "Home")" method="post"></form>
Button4

How to extend ShapeMenuItem with URL field

I'd like to use this existing MenuItem to use shapes for certain menu items. However I'd like a field to input URL like Custom Link has. So I've added new Input field to ShapeMenuItem ... But so far I'm unable to access it's value in shapes themselves
I've tried
<a class="highlight" href="#Model.Content.ContentItem.ShapeMenuItem.Url.Value">#Model.MenuItem.Text</a>
But that gives me server error Cannot perform runtime binding on a null reference
Any ideas?
Ok it was just stupid me again in late hours, it's supposed to be
#Model.MenuItem.Content.ContentItem.ShapeMenuItem.Url.Value

Orchard custom page renders default widgets?

Still getting to know Orchard, I've now managed to create a custom default page using a module and routing rules.
Although Orchard properly shows my page, it also renders three what seem to be default widgets, with the headings "First Leader Aside", "Second Leader Aside", "Third Leader Aside". Ok so apparantly you need to overwite that default behaviour or something like that, but I can't figure out how.
So is there something wrong / missing with my module, or do I need to provide a setting or something like that?
If a widget is in the default layer, it will appear on every single page in the site. See http://docs.orchardproject.net/Documentation/Managing-widgets
You will need to put these widgets in a different layer that is defined by a rule that fits what you want.

How can I use base_path() inside a view in Drupal?

I have the following fields inside a view:
User ID
Teaser
I selected "exclude from display" for the User ID field.
In the Teaser field, I selected the "rewrite the output of this field" option. This way, I can use html to completely control the structure of the view's output. Moreover, I can call the User ID field by using it's token, [uid].
For example, I can do the following in the teaser's rewrite:
Visit Profile
The problem with the above code is that the path is relative. It will only work on the front page of the site.
For example, if this link is clicked in
www.example.com/node/1
then it will visit a non-existent URL of:
node/1/user/[uid]
I have tried the following: http://chopapp.com/#o7osql65
But views fields does not allow PHP codes.
I might be approaching this entirely wrong. Does anyone have any suggestions? Thanks.
You'll want to rewrite the output of the UID field, and have it be rendered as a link. Even if you exclude it from display initially, it will still be available as a link via its token to other fields. One of the options when selecting to 'output this field as a link' is to make the link absolute.

change layout content from controller

I am using Yii. I want to have a dynamic link on a layout. This dynamic link will be modified by controllers. Let's say that dynamic link uses a user's id given by controllers to perform a task.
I am thinking to use jQuery script to get user id returned by controllers then use the user id to modify a div that holds the dynamic link.
What do you think about this technique?
It seems like you want to dynamically change a link AFTER the page is rendered, with client-side JavaScript. But it makes more sense to dynamically render a different link the first time, during the server-size PHP rendering process. The controller generates the view, after all! I would get the user ID from the controller during the page request, pass the ID in to the view, and then build the link in the view dynamically on the initial page load.
If you are modifying a link in a layout (not a view), then the best thing to do is create a variable in the Controller, and set that variable with the view. Look at how Yii uses the $layout, $menu and $breadcrumbs variables to do this.
Assuming that the user is logged in and you want their ID, you can get the ID from the Yii::app() object as well, like so:
<?php echo CHtml::link('Edit user',array('user/edit','userId'=>Yii::app()->user->id)); ?>
But at that point, you can just request the user's ID in the controller, and don't need to build a link like this.
Assuming that you want a different user ID than the logged in user, pass that ID ($userId) from the controller into the view, and just do this (as Moyersy said):
<?php echo CHtml::link('Edit user',array('user/edit','userId'=>$userId)); ?>
This will build the following link (where $userId = 99999999):
Edit user
So when the linked is clicked, in the actionEdit() you now have access to the user's ID via the GET variable $_GET['userId'].
NOW, if what you want to do is change an already created link, then you would need to use jQuery. But you will need to explain in more detail why you are doing this and what is triggering the link change (a dropdown menu?).
I'm sorry, I can't understand what you are trying to do. Specifically I don't understand what a dynamic link is.
Edit:
<? echo CHtml::link('Edit user',array('user/edit','userId'=>$userId)); ?>

Resources