Copied to clipboard

Flag this post as spam?

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


  • Pasang Tamang 258 posts 458 karma points
    Nov 07, 2012 @ 11:40
    Pasang Tamang
    0

    U4.10 BeginForm Issue

    Hi all,

    When I use Html.BeginForm then the form action looks fine but when I use Ajax.BeginForm then form action is not what is required.

     

        using (Html.BeginForm("Login", "AppLogin", FormMethod.Post, new { id = "form" }))
             {
          <input type="text" name="name" id="txtName" />
          <input type="text" name="password" id="txtPassword" />
                <input type="submit" id="btnSubmits" name="btnSubmits" />
             }

     

    Above code parse form action as below:

    <form action="/umbraco/Surface/AppLogin/Login" id="form" method="post" id="form">

    Above form action is fine.

    but when I use 

     using (Ajax.BeginForm("Login", "OnmLogin", new AjaxOptions
             {
                 UpdateTargetId = "loading",
                 HttpMethod = "post",
                 OnBegin = "OnLoginBegin",
                 OnComplete = "OnLoginComplete",
             }, new { id = "FrmTopLogin" }))
             {
    <input type="text" name="name" id="txtName" />
          <input type="text" name="password" id="txtPassword" />
                <input type="submit" id="btnSubmits" name="btnSubmits" />
             }

    The form action is parse as 

    <form action="/Umbraco/RenderMvc/Login?Length=8" data-ajax="true" data-ajax-begin="OnLoginBegin" data-ajax-complete="OnLoginComplete" data-ajax-method="post" data-ajax-mode="replace" data-ajax-update="#loading" id="FrmTopLogin" method="post"> 

    In this second parse form action is not as per my controller.

    Any suggestions please?

    Kind Regards

    PTamang

  • Pasang Tamang 258 posts 458 karma points
    Nov 08, 2012 @ 08:15
    Pasang Tamang
    0

    Any help please?

  • Stephen 767 posts 2273 karma points c-trib
    Nov 08, 2012 @ 09:07
    Stephen
    0

    I have sent it to Shannon (who did the MVC part) so he can have a look. Stay tuned.

  • Pasang Tamang 258 posts 458 karma points
    Nov 08, 2012 @ 14:39
    Pasang Tamang
    0

    Thanks Stephen :) 

  • Shannon Deminick 1524 posts 5269 karma points MVP 2x
    Nov 09, 2012 @ 04:28
    Shannon Deminick
    0

    Hi, ensure you read the documentation here regarding 'BeginUmbracoForm':

    https://github.com/umbraco/Umbraco4Docs/blob/4.8.0/Documentation/Reference/Mvc/forms.md

    Depending on what type of form you are submitting, this will be much nicer to use than using the standard BeginForm.

    As for the Ajax.BeginForm, I can confirm this behavior and it occurs because the Ajax.BeginForm overload you are using is incorrect. I'm assuming you'd like to make the <form id = "FrmTopLogin" ? The overload you are using is this one: http://msdn.microsoft.com/en-us/library/dd504974(v=vs.108).aspx

    public static MvcForm BeginForm(
        this AjaxHelper ajaxHelper,
        string actionName,
        Object routeValues,
        AjaxOptions ajaxOptions,
        Object htmlAttributes
    )

    You need to use a different overload to acheive this, you can see this list here:

    http://msdn.microsoft.com/en-us/library/system.web.mvc.ajax.ajaxextensions.beginform(v=vs.108).aspx

    You can either do this:

    @using (Ajax.BeginForm("Login", "OnmLogin", null, new AjaxOptions
        {
            UpdateTargetId = "loading",
            HttpMethod = "post",
            OnBegin = "OnLoginBegin",
            OnComplete = "OnLoginComplete",
        }, new { id = "FrmTopLogin" }))

    Or this:

    @using (Ajax.BeginForm("Login", new { controller = "OnmLogin" }, new AjaxOptions
        {
            UpdateTargetId = "loading",
            HttpMethod = "post",
            OnBegin = "OnLoginBegin",
            OnComplete = "OnLoginComplete",
        }, new { id = "FrmTopLogin" }))

    Or the other ones that use the IDictionary<string, object> instead of anonymous objects.

    The reason it is showing you the RenderMvc route is because it thinks you are passing in a string object to the object RouteValues parameter which is invalid so it thinks its null so its displaying the default MVC route which currently in this case is the RenderMvc route.

     

     

     


Please Sign in or register to post replies

Write your reply to:

Draft