Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Warren Buckley 2085 posts 4511 karma points MVP 6x admin hq c-trib
    Jun 03, 2013 @ 14:01
    Warren Buckley
    0

    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:

    InvalidOperationException: Sequence contains more than one matching element]
       System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source, Func`2 predicate) +2537270
       Umbraco.Web.Mvc.RenderRouteHandler.HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo) +459
       Umbraco.Web.Mvc.RenderRouteHandler.GetHandlerForRoute(RequestContext requestContext, PublishedContentRequest publishedContentRequest) +129
       Umbraco.Web.Mvc.RenderRouteHandler.GetHttpHandler(RequestContext requestContext) +297
       System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +9709368
       Umbraco.Web.UmbracoModule.RewriteToUmbracoHandler(HttpContextBase context, PublishedContentRequest pcr) +398
       Umbraco.Web.UmbracoModule.ProcessRequest(HttpContextBase httpContext) +729
       Umbraco.Web.UmbracoModule.<Init>b__a(Object sender, EventArgs e) +132
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

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

  • Damiaan 434 posts 1279 karma points MVP 2x c-trib
    Jun 03, 2013 @ 15:14
    Damiaan
    0

    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:

    var surfaceRoute = RouteTable.Routes.OfType<Route>()
                .SingleOrDefault(x => x.Defaults != null &&
                    x.Defaults.ContainsKey("controller") &&
                    x.Defaults["controller"].ToString().InvariantEquals(postedInfo.ControllerName) &&
                    x.DataTokens.ContainsKey("area") &&
                    x.DataTokens["area"].ToString().InvariantEquals(postedInfo.Area));                 

     

    This is not about actions, but it is about controllers and areas.  Is it possible you have defined your controller two times?

  • Warren Buckley 2085 posts 4511 karma points MVP 6x admin hq c-trib
    Jun 03, 2013 @ 15:26
    Warren Buckley
    0

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

  • Kevin Lawrence 183 posts 349 karma points
    Jun 03, 2013 @ 15:33
    Kevin Lawrence
    0

    Hi Warren

    Do you by any chance have a route to your controller action called id?

    Kev

  • Damiaan 434 posts 1279 karma points MVP 2x c-trib
    Jun 03, 2013 @ 15:37
    Damiaan
    0

    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...

     

  • Kevin Lawrence 183 posts 349 karma points
    Jun 03, 2013 @ 15:39
    Kevin Lawrence
    0

    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

  • Shannon Deminick 1484 posts 4984 karma points hq
    Jun 04, 2013 @ 03:03
    Shannon Deminick
    0

    @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.

  • Warren Buckley 2085 posts 4511 karma points MVP 6x admin hq c-trib
    Jun 05, 2013 @ 09:22
    Warren Buckley
    0

    @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
    {
        public class ProfileSurfaceController : SurfaceController
        {
            [Authorize]
            public ActionResult RenderEditProfile()
            {
                ProfileViewModel profileModel = new ProfileViewModel();
    
                //If user is logged in then let's pre-populate the model
                if (Member.IsLoggedOn())
                {
                    //Let's fill it up
                    Member 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 home
                    return Redirect("/");
                }
    
                //Pass the model to the view
                return PartialView("EditProfile", profileModel);
            }
    
            [Authorize]
            public ActionResult 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 email
                Member updateMember = new Member(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();
            }
    
            public ActionResult RenderMemberProfile(string profileURLtoCheck)
            {
                //Try and find member with the QueryString value ?profileURLtoCheck=warrenbuckley
                Member findMember = Member.GetAllAsList().FirstOrDefault(x => x.getProperty("profileURL").Value.ToString() == profileURLtoCheck);
    
                //Create a view model
                ViewProfileViewModel profile = new ViewProfileViewModel();
    
                //Check if we found member
                if (findMember != null)
                {
                    //Increment profile view counter by one
                    int 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 404
                    return new HttpNotFoundResult("The member profile does not exist");
                }
    
                return PartialView("ViewProfile", profile);
    
            }
    
    
            //REMOTE Validation
            public JsonResult CheckEmailIsUsed(string emailAddress)
            {
                //Get Current Member
                var 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 OK
                    if (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(trueJsonRequestBehavior.AllowGet);
                    }
    
                    //Try and get member by email typed in
                    var checkEmail = Member.GetMemberFromEmail(emailAddress);
    
                    if (checkEmail != null)
                    {
                        return Json(String.Format("The email address '{0}' is already in use.", emailAddress),
                                    JsonRequestBehavior.AllowGet);
                    }
    
                    return Json(trueJsonRequestBehavior.AllowGet);
                }
    
                //Unable to get current member to check (just an OK for client side validation)
                //and let action in controller validate
                return Json(trueJsonRequestBehavior.AllowGet);
            }
    
    
            public JsonResult CheckProfileURLAvailable(string profileURL)
            {
                //Get Current Member
                var 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(trueJsonRequestBehavior.AllowGet);
                    }
    
                    //Get all members where profileURL property = value from Model
                    Member checkProfileURL =
                        Member.GetAllAsList().FirstOrDefault(x => x.getProperty("profileURL").Value.ToString() == profileURL);
    
                    //Check not null if not null then its got one in the system already
                    if (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 hood
                    return Json(trueJsonRequestBehavior.AllowGet);
                }
    
                //Unable to get current member to check (just an OK for client side validation)
                //and let action in controller validate
                return Json(trueJsonRequestBehavior.AllowGet);
            }
    
        }
    }
  • David Brendel 749 posts 2816 karma points c-trib
    Jun 24, 2013 @ 16:02
    David Brendel
    0

    Hey Warren,

    do you get this fixed or maybe got a workaround for this problem?

  • Warren Buckley 2085 posts 4511 karma points MVP 6x admin hq c-trib
    Jun 24, 2013 @ 16:04
    Warren Buckley
    0

    No unfortunately not :(

  • David Brendel 749 posts 2816 karma points c-trib
    Jun 24, 2013 @ 17:32
    David Brendel
    0

    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

  • Mark 49 posts 130 karma points
    Jul 13, 2013 @ 04:53
    Mark
    0

    getting this on 6.1.2 - stopped working since upgraded from 6.1.1.

    Have tried renaming controller, no luck.

    Only occurs on postback.

    [InvalidOperationException: Sequence contains more than one matching element]  System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source, Func`2 predicate) +2537238  Umbraco.Web.Mvc.RenderRouteHandler.HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo) +216  Umbraco.Web.Mvc.RenderRouteHandler.GetHandlerForRoute(RequestContext requestContext, PublishedContentRequest publishedContentRequest) +54  Umbraco.Web.Mvc.RenderRouteHandler.GetHttpHandler(RequestContext requestContext) +114  System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +9709884  Umbraco.Web.UmbracoModule.RewriteToUmbracoHandler(HttpContextBase context, PublishedContentRequest pcr) +203  Umbraco.Web.UmbracoModule.ProcessRequest(HttpContextBase httpContext) +374  Umbraco.Web.UmbracoModule.&lt;Init&gt;b__7(Object sender, EventArgs e) +80  System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136  System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +69
  • Mark 49 posts 130 karma points
    Jul 13, 2013 @ 05:16
    Mark
    1

    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
        );
      }
    }
    
  • Steve Temple 54 posts 288 karma points MVP c-trib
    Oct 15, 2013 @ 17:58
    Steve Temple
    0

    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

    surfaceRoute = RouteTable.Routes.OfType<Route>().SingleOrDefault(x => x.Defaults != null &&                                                           x.Defaults.ContainsKey("controller") &&                                                               x.Defaults["controller"].ToString() == postedInfo.ControllerName &&                                                      !x.DataTokens.ContainsKey("area"));      
  • Mark 49 posts 130 karma points
    Oct 15, 2013 @ 21:17
    Mark
    0

    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.

  • Steve Temple 54 posts 288 karma points MVP c-trib
    Oct 15, 2013 @ 21:21
    Steve Temple
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft