You ask me? I feel honored. I am affraid, you know a little bit more of this stuff than I do. ;-)
Are you sure that there is no other controller with the same name? Maybe a namespace collision?
If you can, I would try to hook up the debugger with the original source code to this website. Then you could inspect the RouteTable. Or use GLIMPSE (http://getglimpse.com/) to do this...
@Warren, can you post the definition of your SurfaceController ? Are you using the [PluginController] attribute ? The code that causes this exception would only happen if the controller you are routing to is in an MVC area which can theoretically only happen when using a [PluginController] attribute.
@Shan Here is the entire controller, but noI am not using a PluginController attribute.
Cheers, Warren :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using My.Site.Models;
using Umbraco.Web.Mvc;
using umbraco.cms.businesslogic.member;
namespace My.Site.Controllers.SurfaceControllers
{
publicclassProfileSurfaceController : SurfaceController
{
[Authorize]
publicActionResult RenderEditProfile()
{
ProfileViewModel profileModel = newProfileViewModel();
//If user is logged in then let's pre-populate the modelif (Member.IsLoggedOn())
{
//Let's fill it upMember currentMember = Member.GetCurrentMember();
profileModel.Name = currentMember.Text;
profileModel.EmailAddress = currentMember.Email;
profileModel.MemberID = currentMember.Id;
profileModel.OneLiner = currentMember.getProperty("oneLiner").Value.ToString();
profileModel.Description = currentMember.getProperty("description").Value.ToString();
profileModel.ProfileURL = currentMember.getProperty("profileURL").Value.ToString();
profileModel.Address = currentMember.getProperty("address").Value.ToString();
profileModel.Lat = currentMember.getProperty("memberLat").Value.ToString();
profileModel.Lon = currentMember.getProperty("memberLon").Value.ToString();
profileModel.Twitter = currentMember.getProperty("twitter").Value.ToString();
profileModel.LinkedIn = currentMember.getProperty("linkedIn").Value.ToString();
profileModel.Skype = currentMember.getProperty("skype").Value.ToString();
}
else
{
//They are not logged in, redirect to homereturn Redirect("/");
}
//Pass the model to the viewreturn PartialView("EditProfile", profileModel);
}
[Authorize]
publicActionResult HandleEditProfile(ProfileViewModel model)
{
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
//Update the member with our data & save it down//Using member ID and not email address in case member has changed their emailMember updateMember = newMember(model.MemberID);
updateMember.Text = model.Name;
updateMember.Email = model.EmailAddress;
updateMember.getProperty("oneLiner").Value = model.OneLiner;
updateMember.getProperty("description").Value = model.Description;
updateMember.getProperty("profileURL").Value = model.ProfileURL;
updateMember.getProperty("address").Value = model.Address;
updateMember.getProperty("memberLat").Value = model.Lat;
updateMember.getProperty("memberLon").Value = model.Lon;
updateMember.getProperty("twitter").Value = model.Twitter;
updateMember.getProperty("linkedIn").Value = model.LinkedIn;
updateMember.getProperty("skype").Value = model.Skype;
//Save the member
updateMember.Save();
//Return the view//Update success flag
TempData["IsSuccessful"] = true;
return RedirectToCurrentUmbracoPage();
}
publicActionResult RenderMemberProfile(string profileURLtoCheck)
{
//Try and find member with the QueryString value ?profileURLtoCheck=warrenbuckleyMember findMember = Member.GetAllAsList().FirstOrDefault(x => x.getProperty("profileURL").Value.ToString() == profileURLtoCheck);
//Create a view modelViewProfileViewModel profile = newViewProfileViewModel();
//Check if we found memberif (findMember != null)
{
//Increment profile view counter by oneint noOfProfileViews = 0;
int.TryParse(findMember.getProperty("numberOfProfileViews").Value.ToString(), out noOfProfileViews);
//Increment counter by one
findMember.getProperty("numberOfProfileViews").Value = noOfProfileViews + 1;
//Save it down to the member
findMember.Save();
//Got the member lets bind the data to the view model
profile.Name = findMember.Text;
profile.MemberID = findMember.Id;
profile.EmailAddress = findMember.Email;
profile.OneLiner = findMember.getProperty("oneLiner").Value.ToString();
profile.Description = findMember.getProperty("description").Value.ToString();
profile.Address = findMember.getProperty("address").Value.ToString();
profile.Lat = findMember.getProperty("memberLat").Value.ToString();
profile.Lon = findMember.getProperty("memberLon").Value.ToString();
profile.LinkedIn = findMember.getProperty("linkedIn").Value.ToString();
profile.Skype = findMember.getProperty("skype").Value.ToString();
profile.Twitter = findMember.getProperty("twitter").Value.ToString();
profile.NumberOfLogins = Convert.ToInt32(findMember.getProperty("numberOfLogins").Value.ToString());
profile.IsOnline = Membership.GetUser(findMember.Email).IsOnline;
profile.LastLoginDate = DateTime.ParseExact(findMember.getProperty("lastLoggedIn").Value.ToString(), "dd/MM/yyyy @ HH:mm:ss", null);
profile.NumberOfProfileViews = Convert.ToInt32(findMember.getProperty("numberOfProfileViews").Value.ToString());
}
else
{
//Couldn't find the member return a 404returnnewHttpNotFoundResult("The member profile does not exist");
}
return PartialView("ViewProfile", profile);
}
//REMOTE ValidationpublicJsonResult CheckEmailIsUsed(string emailAddress)
{
//Get Current Membervar member = Member.GetCurrentMember();
//Sometimes inconsistent results with GetCurrent Member, unsure why?!if (member != null)
{
//if the email is the same as the one stored then it's OKif (member.Email == emailAddress)
{
//Email is the same as one currently stored on the member - so email ok to use & rule valid (return true, back to validator)return Json(true, JsonRequestBehavior.AllowGet);
}
//Try and get member by email typed invar checkEmail = Member.GetMemberFromEmail(emailAddress);
if (checkEmail != null)
{
return Json(String.Format("The email address '{0}' is already in use.", emailAddress),
JsonRequestBehavior.AllowGet);
}
return Json(true, JsonRequestBehavior.AllowGet);
}
//Unable to get current member to check (just an OK for client side validation)//and let action in controller validatereturn Json(true, JsonRequestBehavior.AllowGet);
}
publicJsonResult CheckProfileURLAvailable(string profileURL)
{
//Get Current Membervar member = Member.GetCurrentMember();
//Sometimes inconsistent results with GetCurrent Member, unsure why?!if (member != null)
{
if (member.getProperty("profileURL").Value.ToString() == profileURL)
{
//profile URL is the same as one currently stored - so it's ok to use & rule valid (return true, back to validator)return Json(true, JsonRequestBehavior.AllowGet);
}
//Get all members where profileURL property = value from ModelMember checkProfileURL =
Member.GetAllAsList().FirstOrDefault(x => x.getProperty("profileURL").Value.ToString() == profileURL);
//Check not null if not null then its got one in the system alreadyif (checkProfileURL != null)
{
return Json(String.Format("The profile URL '{0}' is already in use.", profileURL),
JsonRequestBehavior.AllowGet);
}
// no profile has this url so its all good in the hoodreturn Json(true, JsonRequestBehavior.AllowGet);
}
//Unable to get current member to check (just an OK for client side validation)//and let action in controller validatereturn Json(true, JsonRequestBehavior.AllowGet);
}
}
}
Actually, just found the problem, error above only occurs when I have the following startup code file included (which works totally fine and appears as if it should be completly unrelated/independant to me...)
public class UmbracoStartup : IApplicationEventHandler {
public void OnApplicationInitialized(UmbracoApplicationBase httpApplication, ApplicationContext applicationContext) {}
public void OnApplicationStarting(UmbracoApplicationBase httpApplication, ApplicationContext applicationContext) {}
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) {
//Register custom MVC route for user profile
RegisterRoutes(RouteTable.Routes);
//ModelBinders.Binders.Add(typeof(IProfileStepModel), new ProfileStepModelBinder());
}
public static void RegisterRoutes(RouteCollection routes) {
//routes.MapRoute(
// "search", // Route name
// "search", // URL with parameters
// new { controller = "Profile", action = "Search" } // Parameter defaults
//);
routes.MapRoute(
"MemberProfile", // Route name
"u/{profileURL}", // URL with parameters
new { controller = "Profile", action = "Profile" } // Parameter defaults
);
}
}
For information this was happening for me on 6.1.6.
It appears to happen when you have multiple routes set with the same controller, the code looks to be finding all routes with the controller name matching and errors if there are multiple routes with the same controller. So this error happens if you manually specify 2 or more routes with the same controller name.
Thanks Steve, however as noted by David it was due to a naming conflict - Only one controller defined (ProfileSurfaceController) and one route defined (see my reply above) and this error is thrown, rename the controller and the problem goes away.
So likely there is an internal 'profilecontroller' of some kind that is causing the conflict.
I've had the same issue where I have 2 routes registered in the global.asax file so in the sample you supplied above if you uncommented the profile search route the error would show up.
I'm having the same issue since upgrading umbraco, routes that used to work now have the error. I've submitted a pull request for version 6.2.0 which fixes the issue: https://github.com/umbraco/Umbraco-CMS/pull/168
Umbraco 6 MVC - RenderRouteHandler.HandlePostedValues Sequence contains more than one matching element
Hello All,
I am creating a simple edit profile form in Umbraco 6 with an MVC SurfaceController.
I am getting the following YSOD when trying to post the form to the Handle POST ActionResult in my controller:
Does anyone have any ideas on this, I have searched though my solution and I definately have only one ActionResult called HandleEditProfile().
Many Thanks,
Warren :)
If I look at the umbraco source code (https://umbraco.codeplex.com/SourceControl/latest#src/Umbraco.Web/Mvc/RenderRouteHandler.cs)
Then I guess that this is the line is failing:
This is not about actions, but it is about controllers and areas. Is it possible you have defined your controller two times?
Hey Damiaan,
As far as I am aware this SurfaceController is only registered the once, but is there anyway for me to verify it though?
Thanks,
Warren :)
Hi Warren
Do you by any chance have a route to your controller action called id?
Kev
You ask me? I feel honored. I am affraid, you know a little bit more of this stuff than I do. ;-)
Are you sure that there is no other controller with the same name? Maybe a namespace collision?
If you can, I would try to hook up the debugger with the original source code to this website. Then you could inspect the RouteTable.
Or use GLIMPSE (http://getglimpse.com/) to do this...
You've just prompted me to raise this as a bug as I hit a similar issue recently:
http://issues.umbraco.org/issue/U4-2313
Kev
@Warren, can you post the definition of your SurfaceController ? Are you using the [PluginController] attribute ? The code that causes this exception would only happen if the controller you are routing to is in an MVC area which can theoretically only happen when using a [PluginController] attribute.
@Shan Here is the entire controller, but noI am not using a PluginController attribute.
Cheers,
Warren :)
Hey Warren,
do you get this fixed or maybe got a workaround for this problem?
No unfortunately not :(
Hey Warren,
got it working. Made a pull request on Github. Test everything proberly.
I think it realy was a nameing conflict. Changed the name of the Controller to MemberSurfaceController and everything is working now.
Regards,
David
getting this on 6.1.2 - stopped working since upgraded from 6.1.1.
Have tried renaming controller, no luck.
Only occurs on postback.
Actually, just found the problem, error above only occurs when I have the following startup code file included (which works totally fine and appears as if it should be completly unrelated/independant to me...)
For information this was happening for me on 6.1.6.
It appears to happen when you have multiple routes set with the same controller, the code looks to be finding all routes with the controller name matching and errors if there are multiple routes with the same controller. So this error happens if you manually specify 2 or more routes with the same controller name.
Line 199 of Umbraco.Web.Mvc.RenderRouteHandler
Thanks Steve, however as noted by David it was due to a naming conflict - Only one controller defined (ProfileSurfaceController) and one route defined (see my reply above) and this error is thrown, rename the controller and the problem goes away.
So likely there is an internal 'profilecontroller' of some kind that is causing the conflict.
I've had the same issue where I have 2 routes registered in the global.asax file so in the sample you supplied above if you uncommented the profile search route the error would show up.
I'm having the same issue since upgrading umbraco, routes that used to work now have the error. I've submitted a pull request for version 6.2.0 which fixes the issue: https://github.com/umbraco/Umbraco-CMS/pull/168
Cheers,
Steve
is working on a reply...