Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC3
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 ? Frown | :(
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 25-Nov-12 3:48am
Dibu.net1.4K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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();
        }
    }
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try with following:
[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[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100