I have two views: order letter
localhost:64351/order-letter
localhost:64351/basket
Both have document type and content in backoffice. I want do in order-letter view button, when I click it I will redirect to basket and I want have available backoffice content. I try do sourface controller and return View
public class MainBasketSourfaceController : SurfaceController
{
public ActionResult Basket()
{
return View("~/Views/Basket.cshtml", new Models.UmbracoModels.BasketRenderModel(CurrentPage));
}
}
But this return error when I using
#CurrentPage
How I can do redirect?
Related
I have crated 1 news item in Sitefinty news content section .How can i get Image of News Author in Sitefinty . I have uploaded my pic in my sitefinty profile and crated 1 news Item but no idea i have for display my image on the news detail page .I am using Sitefinty 6.3.
This will have to be a user control referenced from the news widget details template that looks up the profile that created the news post.
I've got a custom control in my solution at ~/CustomControls/AuthorPicture.ascx, in the ascx file its just a .net image control:
<asp:Image runat="server" ID="imgAuthor" />
In the code behind for the control, use this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Modules.Libraries;
using Telerik.Sitefinity.Modules.News;
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Security.Model;
namespace SitefinityWebApp.CustomControls
{
public partial class AuthorPicture : System.Web.UI.UserControl
{
public Guid NewsId { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (NewsId == Guid.Empty) return;
var newsManager = NewsManager.GetManager();
var newsItem = newsManager.GetNewsItems().FirstOrDefault(n => n.Id == NewsId);
if (newsItem == null) return;
var userManager = UserManager.GetManager();
var upManager = UserProfileManager.GetManager();
var owner = userManager.GetUser(newsItem.Owner);
var profile = upManager.GetUserProfile<SitefinityProfile>(owner);
var lmanager = LibrariesManager.GetManager();
var image = lmanager.GetImage(profile.Avatar.ChildItemId);
imgAuthor.ImageUrl = image.ThumbnailUrl;
}
}
}
You can see that we'll be passing in the news item id through the NewsId Guid property on the control.
To just show how this works, create a page in Sitefinity and add a News widget on to the page. Click "Edit" select "One particular news item" and select your news item. Under the "Single Item Settings" tab select your details template, the default name is "Full News Item". Click "Edit Selected Template" and register your control in the template:
<%# Register TagPrefix="custom" TagName="AuthorImage" Src="~/CustomControls/AuthorPicture.ascx" %>
Then somewhere in the RadListView itemTemplate, use the control and pass in the news Id to the property:
<custom:AuthorImage runat="server" ID="cstmAuthorImage" NewsId='<%# Eval("Id") %>' />
Save the changes and publish your page, your new control should be run, and it should pull the profile image of whoever created the post.
I found something similar in Sitefinity forums here: http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/retrieving-post-author-details-avatar-nickname-etc-in-blog-post-templates
I would probably create a new template for the News detail. Inside here you can attach to the ItemDataBound event where you can set an image for the news item.
The Author field has no relation to a Sitefinity User, so you need to get the ID of the user that created the Newsitem. (the owner)
This code shows you how to do this:
protected void Repeater_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e) {
var data = ((RadListViewDataItem)e.Item).DataItem as NewsItem;
// Get the owner
var owner = userManager.GetUser(data .Owner);
}
The logic for retrieving a user and an image you can find in the code from Ben.
Another way would be to create a custom field which shows you a UserPicker field, which would then allow you to be completely flexible on choosing which Sitefinity User you will relate to a news item.
I want to implement menu in GWT as shown on this website:
http://www.openkm.com/en/
I have created the menu system and I am able to display alerts from menu using following code:
Command cmd = new Command() {
public void execute() {
Window.alert("Menu item have been selected");
}
}
I want to get rid of window.alert() and display my application pages from menu.
Create and load the appropriate page. For example if you use UiBinder then:
MyPage selectedPage = new MyPage(); // creating of your panel
RootPanel.get().clear(); // cleaning of rhe RootPanel
RootPanel.get().add(selectedPage); // adding the panel to the RootPanel
First create an array list of views
public List<UIObject> viewsList = new ArrayList<UIObject>();
Add a view to that list
viewsList.add(addMovieView);
Send the view you want to select to the helper method
public void changeView(UIObject selectedView) {
for(UIObject view : viewsList) {
if(selectedView.equals(view)) {
view.setVisible(true);
} else {
view.setVisible(false);
}
}
}
Are you trying to make the entire page GWT, or just the menu? If it's just the menu, you will need to embed a GWT element into your overall HTML, then call something like
Window.open(linkURL, "_self", "");
from the appropriate menu items, which will navigate to another page.
I'm new to FubuMvc and I'm just playing around with it on a small project.
I have the default nuget package fubu configuration, and I'm using web forms view engine:
public ConfigureFubuMVC()
{
// This line turns on the basic diagnostics and request tracing
IncludeDiagnostics(true);
// All public methods from concrete classes ending in "Controller"
// in this assembly are assumed to be action methods
Actions.IncludeClassesSuffixedWithController();
// Policies
Routes
.IgnoreControllerNamesEntirely().IgnoreControllerFolderName()
.IgnoreMethodSuffix("Html")
.RootAtAssemblyNamespace();
// Match views to action methods by matching
// on model type, view name, and namespace
Views.TryToAttachWithDefaultConventions();
// View Engine
this.Import<WebFormsEngine>();
}
I've created a controller and a view in my site root, like so:
~/IndexController.cs
namespace MovieApp
{
public class IndexController
{
private MoviesDBEntities _db = new MoviesDBEntities();
public MovieIndexViewModel Index()
{
return new MovieIndexViewModel { Movies = _db.Movies.ToList() };
}
public class MovieIndexViewModel
{
public IEnumerable<Movie> Movies { get; set; }
}
}
}
and the View that goes with it:
~/Index.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" MasterPageFile="/Site.Master" Inherits="MovieApp.Index" %>
...
When I browse to ~/Index it works fine.
Now I want to move my controller into a new folder, "Movies". So I move the controller and the view, and I change the namespace on the controller to be MoviesApp.Movies.
When I navigate to ~/Movies/Index, it hits a breakpoint in my IndexController.Index() ActionMethod, but then a 404 is displayed.
Any ideas?
I assume that you're using the WebForms engine, right? For WebForms view resolution, FubuMVC makes the assumption that the namespace of the view exactly matches the view location. When you moved the views around those two things no longer match. If you've got R# installed, just open the code behind and have it adjust the Namespace -- and make sure the namespace gets changed on the aspx as well.
The better advice is probably to switch to the Spark view engine or Razor support in FubuMVC is already in flight.
I have an action method that I need to execute when the back button is clicked. I've done this before by disabling the cache in my action method (Response.Cache.SetCacheability(HttpCacheability.NoCache). This isn't working for a different action method. For some reason when i disable the cache and hit the back button to trigger my action method the page expires. Any ideas on what the issue may be?
Try the following, works great for me:
public class NoCacheAttribute : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
var response = filterContext.HttpContext.Response;
response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
response.Cache.SetValidUntilExpires(false);
response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
response.Cache.SetCacheability(HttpCacheability.NoCache);
response.Cache.SetNoStore();
}
}
public class HomeController : Controller
{
[NoCache]
public ActionResult Index()
{
// When we went to Foo and hit the Back button this action will be executed
// If you remove the [NoCache] attribute this will no longer be the case
return Content(#"Go to foo<div>" + DateTime.Now.ToLongTimeString() + #"</div>", "text/html");
}
public ActionResult Foo()
{
return Content(#"Go back to index", "text/html");
}
}
There is no way to know, on the server side, if the page request was the result of the back button or not.
More than likely, the previous request was a post rather than a get, and the post requires that you repost the data.
public ActionResult Home()
{
return View();
}
This is what I have for my current site within the HomeController. How can I detect if the action is called from a mobile device, and if it is, re-direct to MobileHome.aspx instead of Home.aspx.
I don't need to know the details of the device, because I am implementing the view in JQuery Mobile, which should adjust itself correctly depending on the view it's rendered in.
You may find the following blog post useful.
The following is an override on the Controller class. I have not tested this, so consider it pseudo code:
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (this.Request.Browser.IsMobileDevice && filterContext.Result is ViewResultBase)
{
var viewResult = filterContext.Result as ViewResultBase;
viewResult.ViewName = "Mobile" + viewResult.ViewName;
}
base.OnActionExecuted(filterContext);
}
You can use the Request.Browser.IsMobileDevice to determine if the device is mobile (obviously), and then check to see if the result it a view. However, changing the view name is not sufficient if you pass an actual view to the result of your action.