Encountering a 404 error in Angular MVC project while trying to load a

Trying to access an edit partial named AddEditPersonModal.cshtml from a different folder in my MVC project, in order to load its contents into a UI Bootstrap modal using Angular. However, when the index.cshtml page loads, I encounter a 404 error related to that particular partial. Below is the code snippet:

Angular:

 $scope.editPerson = function (person) {
    $scope.modalModel = person;
    //getModal(person);
    $uibModal.open({
        templateUrl: '/Modal/AddEditPersonModal.cshtml',
        controller: 'modalController',
        scope: $scope
    })
    resolve: {
            person: {
                return $scope.person;
            }
    }
}

Index.cshtml

<a href="" data-toggle="modal" data-target="#myModal" ng-model="editPersonModel" ng-click="editPerson(person)"><span class="fa fa-pencil-square-o"></span></a>

Error:

    angular.js:12011 GET http://localhost:58227/Modal/AddEditPersonModal.cshtml 404 (Not Found)(anonymous function) @ angular.js:12011n @ angular.js:11776(anonymous function) @ angular.js:11571(anonymous function) @ angular.js:16383$eval @ angular.js:17682$digest @ angular.js:17495scopePrototype.$digest @ hint.js:1364$apply @ angular.js:17790scopePrototype.$apply @ hint.js:1427(anonymous function) @ angular.js:25890dispatch @ jquery-1.12.4.min.js:3r.handle @ jquery-1.12.4.min.js:3
angular.js:13920 Error: [$compile:tpload] http://errors.angularjs.org/1.5.8/$compile/tpload?p0=%2FModal%2FAddEditPersonModal.cshtml&p1=404&p2=Not%20Found
    at angular.js:38
    at angular.js:19433
    at angular.js:16383
    at m.$eval (angular.js:17682)
    at m.$digest (angular.js:17495)
    at m.scopePrototype.$digest (hint.js:1364)
    at m.$apply (angular.js:17790)
    at m.scopePrototype.$apply (hint.js:1427)
    at l (angular.js:11831)
    at J (angular.js:12033)

ModalController:

 [HttpPost]
    public ActionResult AddEditPersonModal(DTOPerson model)
    {
        return View(model);
    }

Answer №1

When working with MVC architecture, it is important to remember that you navigate to controller methods that return views, rather than directly to the view file itself. To address this issue in your script, make the following adjustments:

$uibModal.open({
    templateUrl: '/Modal/AddEditPersonModal', // update this
    controller: 'modalController',
    scope: $scope
})

Additionally, ensure that you remove the [HttpPost] attribute from your AddEditPersonModal() method. This is necessary because the request being made is a GET request, not a POST.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Capturing groups in Javascript Regex not populating back-references correctly

Here's an interesting situation (or maybe not so uncommon): I'm trying to extract two specific capturing groups using JavaScript regex. The first group should consist of one or more digits (0-9), while the second group should consist of one or mo ...

Enhancing link functionality with jQuery on a dynamically generated server page

I am facing an issue with my navigation menu that includes dropdowns. On desktop, the parent items need to be clickable as well, which is not a problem. However, for it to be responsive on mobile devices, I need to account for the lack of hover capability. ...

Incorporating Numerous Location Pointers in Angular-google-maps

I've been struggling to show multiple map markers in my Angular project. I have a service called retsAPI that queries a local MLS database for home listings, and I'm attempting to display these items on a Google map. Below is my controller code. ...

Center-align the table element

I've been struggling to center align this table element, specifically the one containing the square, but nothing seems to be working. Can anyone lend a hand in fixing this issue? <table> <tbody> <tr> <td>TURKEY - SU ...

Why are my values not being applied to the model class in Angular 7?

I'm currently developing an online shopping website where I have defined my order Model class as shown below: import { User } from './user.model'; export class Order { constructor(){} amount: Number = 0; status: String = ""; date: ...

The functionality of Ajax is currently disabled on the latest mobile Chrome browsers

I have successfully created a modal form with dependent dropdown lists, and I am populating these lists using an ajax call. The functionality works smoothly on desktop browsers and most mobile browsers, but there seems to be an issue on certain newer versi ...

Mongoose parameters do not accept passing an id or element

When working with MongoDB and using mongoose, I attempted to remove an item from a collection by utilizing the findByIdAndDelete() method. However, I encountered the following error: CastError: Cast to ObjectId failed for value "5f080dd69af4c61774ef447f" a ...

Declaring a variable outside of a function or object

It's been a challenge for me to assign a value to the variable result as it always stays undefined. if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } ...

Integrating Node.js with static HTML documents

I'm currently exploring methods for making node.js API calls from static HTML. While I've considered using Express and similar template engines, I am hesitant since they would require me to adjust my existing HTML to fit their templates. Typicall ...

Retrieving POST data from AngularJS AJAX in Python FlaskExplanation: In this

Utilizing Angular's AJAX call, I am sending data to my Flask backend for natural language processing. Here is the AJAX code snippet: $scope.processText = function(){ $http({ method: "POST", url: "http://127.0.0.1:5000/processTex ...

Using Nested ng-repeat for Values and Keys in Angular

Struggling with implementing nested ng-repeats in my code. I have a JSON object with multiple layers and attempting to iterate through them to display the data. Here is the structure of the JSON: { "status": "success", "data": { "Mat": { "tota ...

Avoid triggering the API with rapid successive clicks

My project involves creating an Instagram-clone with like and dislike buttons. When a user is logged in and hasn't liked or disliked a post yet, both buttons appear as black. If the user likes a post, the like button turns blue, and if they click disl ...

How to easily open a search page with just a click on the search field in CodeIgniter?

I am in the process of implementing a search feature in CodeIgniter. My view file is divided into two main sections: Header section, which includes the search bar <?php echo form_open('controller/live_search');?> <div class="toolba ...

Send error messages directly to the client side or retrieve status codes and messages

When responding to an AJAX request, encountering an app error like data validation failure can be tricky. How can we effectively communicate this to the user? 1. Returning a Status Code and Fetching Message with JS $.ajax(options).done(function(response) ...

Locate the generated ID of the inserted child when saving the parent in MongoDB

If I have a document representing a post with comments like the one below: { "_id": "579a2a71f7b5455c28a7abcb", "title": "post 1", "link": "www.link1.com", "__v": 0, "comments": [ { "author": "Andy", "body": "Wis ...

Using JavaScript in conjunction with IPFS to verify the 404 status from localhost:8080 and identify if the local IPFS node is active within a browser user script

As a newcomer to IPFS and JavaScript, I have successfully created a simple IPFS userscript that redirects addresses containing *://*/ipfs/* or *://*/ipns/* to http://localhost:8080/<IPFS_HASH>. However, there is an issue when the local IPFS node is ...

React component failing to update upon rerender

I've encountered an issue with my Flux setup where the component doesn't rerender when adding a new Todo, although it does when deleting or changing the checkbox. I find this behavior confusing and wonder what might be causing it. The list itself ...

AngularJS Toggle Directive tutorial: Building a toggle directive in Angular

I'm attempting to achieve a similar effect as demonstrated in this Stack Overflow post, but within the context of AngularJS. The goal is to trigger a 180-degree rotation animation on a button when it's clicked – counterclockwise if active and c ...

VueJS is unable to identify the variable enclosed within the curly braces

I recently started learning VueJS and I've hit a roadblock. My goal is to display a variable, but for some reason, instead of seeing the product name, all I get is {{product}} Here's the HTML code I'm using: <!DOCTYPE html> <html l ...

What is the correct way to implement ng-repeat with this JSON object?

I stumbled upon a "ng-repeat test fiddle" while browsing Google, and decided to update it by adding double quotes similar to the format of my json string: http://jsfiddle.net/tRxzr/602/ However, the version I created doesn't seem to be functioning pr ...