Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I am using strongly typed view , resource not found error occurred
please help me to resolve this ..

few days ago i installed mvc 3 tools update . why this is happening ? is there any fault in my computer or some files of my VS10 are corrupted ?

localhost:1590/Logins/NewLogin

tell me where is my fault ? :(
there is my code

-----------------------
Model :
----------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace SimpleLogin.Models
{
    public class LoginModel
    {
        private string user_ID;
        [Required]
        [DisplayName("User ID:")]
        
        public string User_ID
        {
            get { return user_ID; }
            set { user_ID = value; }
        }
        private string password;
        [Required]
        [DisplayName("Password:")]
        [DataType(DataType.Password)]

        public string Password
        {
            get { return password; }
            set { password = value; }
        }

    }
}


------------------------------
Controller :
-----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SimpleLogin.Models;
namespace SimpleLogin.Controllers
{
    public class LoginsController : Controller
    {
        //
        // GET: /Logins/

        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult NewLogin(LoginModel m)
        {
            if (m.User_ID == "admin" && m.Password == "pass") 
            {
            
            }
            return View();
        }
    }
}

---------------------
View :
--------------------
@model SimpleLogin.Models.LoginModel

@{
    ViewBag.Title = "NewLogin";
}

@using (Html.BeginForm())
{ 
    <table>
        <tr>
            <td>
                @Html.LabelFor(x=>x.User_ID)
            </td>
            <td>
                @Html.TextBoxFor(x=>x.User_ID)
            </td>
        </tr>
        <tr>
            <td>
                @Html.LabelFor(x=>x.Password)
            </td>
            <td>
                @Html.TextBoxFor(x=>x.Password)
            </td>
        </tr>
    </table>
}
Posted

In your Controller you need to add HTTPGET method for NEWLOGIN Action
Change your controller like below...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SimpleLogin.Models;
namespace SimpleLogin.Controllers
{
    public class LoginsController : Controller
    {
        //
        // GET: /Logins/

        public ActionResult Index()
        {
            return View();
        }
	[HttpGET]
        public ActionResult NewLogin()
        {
            return View();
        }
        [HttpPost]
        public ActionResult NewLogin(LoginModel m)
        {
            if (m.User_ID == "admin" && m.Password == "pass") 
            {
            
            }
            return View();
        }
    }
}
 
Share this answer
 
v2
Try with following:
C#
[AllowAnonymous]
[HttpPost]
public ActionResult NewLogin(LoginModel m)
 {
    if (m.User_ID == "admin" && m.Password == "pass")
    {

    }
   return View();
 }

Read more detail:
http://msdn.microsoft.com/en-us/library/system.web.http.allowanonymousattribute%28v=vs.108%29.aspx[^]
http://blogs.msdn.com/b/rickandy/archive/2011/05/02/securing-your-asp-net-mvc-3-application.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900