Copied to clipboard

Flag this post as spam?

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


  • Michael 22 posts 61 karma points
    May 20, 2015 @ 12:50
    Michael
    0

    Validation in partial view.

    Hello, everyone, I don't know much about MVC using in Umbraco.

    I implemented my membership function by searching the google,

    I create a "Login" template as following.

     I used @Html.Partial method to render my partial view -"MemberLogin.cshtml" , second diagram.

    The following is my code in Controller.

            [HttpGet]

            //[ActionName("MemberLogin")]

            public ActionResult MemberLogin(string username)

            {

                MemberLoginModel model = new MemberLoginModel();

                //if (!string.IsNullOrEmpty(username))

                //    model.Username = username;

                return PartialView("MemberLogin", model);

            }

     

            [HttpPost]

            public ActionResult MemberLogin(MemberLoginModel model)

            {

                if (ModelState.IsValid)

                {

                    if (Membership.ValidateUser(model.Username, model.Password))

                    {

                        FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);

                        return RedirectToUmbracoPage(1063); //RedirectToAction("MemberLogin", "MemberLoginSurface"); //

                    }

                    else

                    {

                        TempData["Status"] = "Invalid username or password";

                        return PartialView("MemberLogin");

                    }

                }

                else

                {

                    return PartialView(model);

                }

            }

    I can see my Login page.

    but my validation doesn't work and I redirect to my partial page wihtout css like the following diagram.

    I can't find where were my mistakes. Hope someone can help me. Thank you in advanced!

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 20, 2015 @ 14:24
    Alex Skrypnyk
    0

    Hi Michael,

    1) Why do you see page without styles ? It's because you return partial view in result of your actions, you have to return all page or another solution is to make request by ajax.

    2) Validation isn't working, do you have some js erros ?

    Thanks, Alex

  • Michael 22 posts 61 karma points
    May 21, 2015 @ 04:59
    Michael
    0

    Thanks very much Alex! Yes. I totally agree with your point of view.

    I return partial view in result of my actions. How can I return all page via using umbraco API?

    I didn't use client-side validation,but use data annotation in the model.

        public class MemberLoginModel

        {

            [Required, Display(Name = "Enter your user name")]

            public string Username { get; set; }

            [Required, Display(Name = "Password"), DataType(DataType.Password)]

            public string Password { get; set; }

            [Display(Name = "Remember me")]

            public bool RememberMe { get; set; }

        }

    I'm not familiar with the umbraco API, especially in MVC,  it's hard to integrate MVC and Umbraco for me.

    Could you give me a simple or some links related to it.

    Thanks very much!

     

Please Sign in or register to post replies

Write your reply to:

Draft