Click here to Skip to main content
14,661,411 members
Home » Discussions » .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Best practice connecting to database Pin
Eddy Vluggen9-Aug-17 8:25
professionalEddy Vluggen9-Aug-17 8:25 
QuestionHow to get each items "valuemember" value of checkedlistbox using for loop and show it in messagebox in winform Pin
bhagyashri from kolhapur19-Jul-17 2:33
Memberbhagyashri from kolhapur19-Jul-17 2:33 
AnswerRe: How to get each items "valuemember" value of checkedlistbox using for loop and show it in messagebox in winform Pin
Richard MacCutchan19-Jul-17 4:56
mveRichard MacCutchan19-Jul-17 4:56 
QuestionOne Wier library for VB.NET Pin
Member 1218072911-Jul-17 23:47
MemberMember 1218072911-Jul-17 23:47 
AnswerRe: One Wier library for VB.NET Pin
Afzaal Ahmad Zeeshan12-Jul-17 0:30
mvaAfzaal Ahmad Zeeshan12-Jul-17 0:30 
GeneralRe: One Wier library for VB.NET Pin
Member 1218072920-Jul-17 6:01
MemberMember 1218072920-Jul-17 6:01 
QuestionMVC: ValidationSummary("); dosn't work with Partial Viwe Pin
Azza ALbelushi5-Jul-17 23:55
MemberAzza ALbelushi5-Jul-17 23:55 
AnswerRe: MVC: ValidationSummary("); dosn't work with Partial Viwe Pin
Richard Deeming6-Jul-17 1:22
mveRichard Deeming6-Jul-17 1:22 
When you call the View method[^] without specifying a view name, it tries to find a view that matches the action name. You can see the list of views it looked for in the error message.

The problem is, you don't have a view called either Login or Register, so when you call View from those actions, it won't be able to find a matching view.

You can either add the missing views:

Login.cshml:
@{
    ViewBag.Title = "Login";
}
 
@section PageHeader
{
    <link href="~/Content/Css/Login.css" rel="stylesheet" />
    <link href="~/Content/Css/animation.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
 
}
 
@{ Html.RenderPartial("_Login"); }

Register.cshtml:
@{
    ViewBag.Title = "Register";
}
 
@section PageHeader
{
    <link href="~/Content/Css/Login.css" rel="stylesheet" />
    <link href="~/Content/Css/animation.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
 
}
 
@{ Html.RenderPartial("_Register"); }


Or, you can specify the view name:
public class AccountController : Controller
{
    public ActionResult MainLoginPage()
    {
        return View();
    }
    
    [HttpPost]
    public ActionResult Login(UserInfo user)
    {
        if (Membership.ValidateUser(user.UserName, user.Password))
        {
            FormsAuthentication.SetAuthCookie(user.UserName, false);
            return RedirectToAction("HomePage", "Home");
        }
        
        ModelState.AddModelError("", "Login details are wrong.");
        return View("MainLoginPage", user);
    }
    
    [HttpPost]
    public ActionResult Register(UserInfo user)
    {
        if (ModelState.IsValid)
        {
            MembershipCreateStatus status;
            Membership.CreateUser(user.UserName, user.Password, user.Email, null, null, true, out status);
            switch (status)
            {
                case MembershipCreateStatus.Success:
                {
                    return RedirectToAction("HomePage", "Home");
                }
                case MembershipCreateStatus.InvalidUserName:
                {
                    ModelState.AddModelError(nameof(UserInfo.UserName), "Invalid username.");
                    break;
                }
                case MembershipCreateStatus.InvalidPassword:
                {
                    ModelState.AddModelError(nameof(UserInfo.Password), "Invalid password.");
                    break;
                }
                case MembershipCreateStatus.InvalidEmail:
                {
                    ModelState.AddModelError(nameof(UserInfo.Email), "Invalid email address.");
                    break;
                }
                case MembershipCreateStatus.DuplicateUserName:
                {
                    ModelState.AddModelError(nameof(UserInfo.UserName), "Already registered.");
                    break;
                }
                case MembershipCreateStatus.DuplicateEmail:
                {
                    ModelState.AddModelError(nameof(UserInfo.Email), "Already registered.");
                    break;
                }
                case MembershipCreateStatus.UserRejected:
                {
                    ModelState.AddModelError("", "User rejected.");
                    break;
                }
                default:
                {
                    ModelState.AddModelError("", "Unknown error.");
                    break;
                }
            }
        }
        
        return View("MainLoginPage");
    }
}

NB: In this case, you'll also want to remove the GET versions of Login and Register, since you don't have separate views for them.

You also need to verify the status when registering a new user, using the MembershipCreateStatus enum.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: MVC: ValidationSummary("); dosn't work with Partial Viwe Pin
Azza ALbelushi6-Jul-17 2:49
MemberAzza ALbelushi6-Jul-17 2:49 
GeneralRe: MVC: ValidationSummary("); dosn't work with Partial Viwe Pin
Richard Deeming6-Jul-17 2:52
mveRichard Deeming6-Jul-17 2:52 
GeneralRe: MVC: ValidationSummary("); dosn't work with Partial Viwe Pin
Azza ALbelushi6-Jul-17 8:00
MemberAzza ALbelushi6-Jul-17 8:00 
GeneralRe: MVC: ValidationSummary("); dosn't work with Partial Viwe Pin
Richard Deeming6-Jul-17 9:07
mveRichard Deeming6-Jul-17 9:07 
GeneralRe: MVC: ValidationSummary("); dosn't work with Partial Viwe Pin
Azza ALbelushi6-Jul-17 19:07
MemberAzza ALbelushi6-Jul-17 19:07 
GeneralRe: MVC: ValidationSummary("); dosn't work with Partial Viwe Pin
Richard Deeming7-Jul-17 0:29
mveRichard Deeming7-Jul-17 0:29 
GeneralRe: MVC: ValidationSummary("); dosn't work with Partial Viwe Pin
Azza ALbelushi10-Jul-17 20:05
MemberAzza ALbelushi10-Jul-17 20:05 
GeneralRe: MVC: ValidationSummary("); dosn't work with Partial Viwe Pin
Richard Deeming11-Jul-17 1:29
mveRichard Deeming11-Jul-17 1:29 
GeneralRe: MVC: ValidationSummary("); dosn't work with Partial Viwe Pin
Dave Kreskowiak11-Jul-17 3:33
mveDave Kreskowiak11-Jul-17 3:33 
QuestionPrinting things in MVC Pin
kijie4-Jul-17 5:33
Memberkijie4-Jul-17 5:33 
AnswerRe: Printing things in MVC Pin
Gerry Schmitz4-Jul-17 6:03
mveGerry Schmitz4-Jul-17 6:03 
QuestionConsole Application is raising following Error Pin
indian14329-Jun-17 7:54
Memberindian14329-Jun-17 7:54 
AnswerRe: Console Application is raising following Error Pin
jschell2-Jul-17 7:18
Memberjschell2-Jul-17 7:18 
QuestionTelerik radscheduler day view problem Pin
Member 1326557818-Jun-17 1:50
MemberMember 1326557818-Jun-17 1:50 
AnswerRe: Telerik radscheduler day view problem Pin
Eddy Vluggen18-Jun-17 2:37
professionalEddy Vluggen18-Jun-17 2:37 
GeneralRe: Telerik radscheduler day view problem Pin
Member 1326557818-Jun-17 2:51
MemberMember 1326557818-Jun-17 2:51 
GeneralRe: Telerik radscheduler day view problem Pin
Eddy Vluggen18-Jun-17 3:03
professionalEddy Vluggen18-Jun-17 3:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.