-5

I posted my observables from js to server-side. But I got this error message from firebug.

"POST http://localhost:54964/Administration/User/CreateUser" 404 Not Found

UserModel.js (my knockoutjs)

return function () {
    var self = this;
    self.email = ko.observable("");
    self.password = ko.observable("");

    self.createUser = function () {
        console.log("hey");
        webRequest.postJSON("/Administration/User/CreateUser", ko.toJSON(self), self.saveSucceeded);
    }

    self.saveSucceeded = function (result) {
        utils.showSuccess("OK..");
        window.location.href = "http://" + window.location.host + "/#/Administration/AllUsers";
    }
}

I have UserController.cs and CreateUser action in it. However I got this error. My action method cannot be found.

sent observables by a viewmodel

AddUserModel.cs

public class AddUserModel
    {
        [Required(ErrorMessage = "Eposta alanı boş olamaz.")]
        [RegularExpression(@"^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$", ErrorMessage = "Geçerli bir e-posta adresi giriniz")]
        public string Email { get; set; }

        [Required(ErrorMessage = "Şifre alanı boş olamaz.")]
        public string Password { get; set; }
    }

And the method that creates an user in the controller.

UserController.cs

[HttpPost]
  public ActionResult CreateUser(AddUserModel model)
        {
            MembershipCreateStatus status;
            Membership.CreateUser(model.Email, model.Password, model.Email, null, null, true, out status);
            if (status == MembershipCreateStatus.Success)
            {
                return Json(true);
            }
            else
            {
                return new Json(false);
            }
        }

NOTE: Administration was a "Folder". I changed it as "Area" for area registration. Therefore I deleted Administration "Folder" then added Administration "Area". This may be a reason. I don't know.

Error message= The controller for path '/Administration/User/CreateUser' was not found or does not implement IController.

Why can't controller or action being found?

user2923864
  • 179
  • 2
  • 4
  • 12
  • 3
    How are we supposed to know? We don't have access to your code (hint: start by posting your MVC routes). – Ant P Jan 16 '15 at 17:24
  • not neccessary to post my routes, I just want to say that before I converted Administiration "Folder" to Administiration "Area", my program was working well. After I did this, It didn't work. As I mentioned my post. – user2923864 Jan 16 '15 at 17:29
  • You think irrelevant details of what your client-side code is doing before and after making a POST request to your MVC app is more important to solving the problem of an action not being hit than your routing? No wonder your code doesn't work ;) – Ant P Jan 16 '15 at 17:50

1 Answers1

0

Within your area you will and you should have a file called AdministrationAreaRegistration.cs

In that file you should define your routes, something like this:

public class AdministrationAreaRegistration : AreaRegistration
{
     public override string AreaName{
          get{ "Administration"}
     }

     public override void RegisterArea(AreaRegistrationContext context){
          context.MapRoute(
               "Administration_default",
               "Administration/{controller}/{action}/{id}",
               new { action = "Index", id = UrlParameter.Optional},
               new [] { "YourControllerNamespace" }
          );
     }


}

Read more here about area registration.

Make sure that in this file App_Start/RouteConfig.cs you have this line:

AreaRegistration.RegisterAllAreas();

within the RegisterRoutes method.

Community
  • 1
  • 1
Cacho Santa
  • 6,846
  • 6
  • 41
  • 73
  • I did it. When I created the project first, I added a folder named Administiration. After I needed AdministrationAreaRegistration file, so to do this I deleted Administration folder and I created an area named Administiration with AdministrationAreaRegistration. I copied folders to this new area. After all these my js started not to post. – user2923864 Jan 16 '15 at 17:34
  • update my answer. Post more code, is hard to help you like this. @user2923864 – Cacho Santa Jan 16 '15 at 17:39