i have created a default MVC 5 project. i used Entity Framework 6. I created a simple person class with Id and Name as a model. Then i generated CRUD operation for it using MVC 5 template after running the code first migration. i implemented a delete functionality everything is working fine.
but when i copied the same code other MVC project. but this project contains some additional css and js. whenever i click on delete or any other operation page is posting back. i want to know why it is happening and why default project has every thing enabled with Ajax.
what i am missing in this project
To enable ajax helpers:
Install-Package microsoft.jQuery.Unobtrusive.Ajax
Related
I upgraded an ASP.NET Core 2.2 MVC project to 3.0 in order to use a Blazor component in one of the views of the application. After setting up Blazor in the MVC project and running it, the Blazor hub connects just fine as shown in the browser console screenshot below:
but when I navigate to the page that contains the blazor component or another page besides the index page for that matter, I get this:
As shown in the screenshot, it includes the name of the controller the url that negotiates for a websocket connection and throws a 404. If this is not a bug, how can I fix this to work on every view of the application or the view that contains my component to say the least?
What I needed to do was to set the app base path in shared.chtml and Boom! Problem Solved.
I just wonder how to do some events with Javascript Apache Cordova project on Visual Studio
Do i need to create new js file for each html file (like Controller - View on MVC)
What is the events fire sort ? (Which event first, which event next firing )
I do same sample, i put one button and when i click button i open new page, when i fire backbutton, first page comes, but button on the first page not working anymore, what is wrong ?
And at last, how can store some data on SQLite database localy and do some read,write,list actions ? Is there any sample code with these ?
Thanks everybody,
Do i need to create new js file for each html file (like Controller - View on MVC).
It's not necessary, you can put all code to one .js file. Depends on your coding style and used framework.
What is the events fire sort ? (Which event first, which event next firing ).
Cordova app, in fact, is a web page in mobile browser. So you should read proper docs. For special Cordova events see this page: http://cordova.apache.org/docs/en/4.0.0/cordova_events_events.md.html#Events
I do same sample, i put one button .....
First af all, it's recommended to use Single-Page-Application, for details see there: http://cordova.apache.org/docs/en/4.0.0/guide_next_index.md.html#Best%20Practices. As for your app, you shoukd provide some more details. Looks, like you missed some script or link while reloading first page.
how can store some data on SQLite database localy
First, read this page about storage: http://cordova.apache.org/docs/en/4.0.0/cordova_storage_storage.md.html#Storage. It's recommended to use WebSQL, but you can try this plugin: https://github.com/brodysoft/Cordova-SQLitePlugin, or read this article about WebSQL: http://msopentech.com/blog/2014/05/05/websql-plugin-for-apache-cordova/
I am adding some functionality to an existing Microsoft MVC 3 application. I cannot change the existing structure of the app itself while I do need to add some new functionality to the page. I have angular running in a div (hidden on load via jquery dialog). The MVC app has several tabs on the page. Each time a tab is chosen, the a partial cshtml (razor) loads. Along with that partial, my angular template is included. The partial references a js file that contains the angular controller. When it is first loaded and the user opens the tab and open the jquery dialog containing angular, everything works fine. I started to notice some funny behavior after the changes are saved. I noticed the same irregular behavior if I closed the dialog containing the angular template, switched to another tab, then switched back to the tab containing the angular template. Here's what is happening:
The partial being loaded by MVC reloads the angular template which initiates the angularjs controller method in the referenced js file
A new $scope is being generated each time this occurs.
Each time a controller method is invoked (via ng-click event tied to a button on the template) teh method will execute n number of times with n being the number of times the partial has been loaded since the last full page refresh.
I proved this method by logging the $scope object to the window in the start of the controller method
window['scope_' + new Date().getTime().toString()] = $scope;
After each partial page load, a new $scope object is logged to the window. Pressing a button on the template invoked a certain method tied to the ng-click event. This event fires multiple times. But calling the method manually in the console using the oldest recorded scope object in the window
scope_1378413848781.$apply(scope_1378413848781.getSomeData())
it works as intended. So, my question is, how do I prevent the controller from adding a new scope every time the MVC framework reloads the partial?
Here are some of the things I've tried that didn't work:
Adding a global flag and exiting the controller method if it was set
moving the controller reference to the _layout.cshtml file
destroying the scope when the dialog containing the template is closed
One final note, I am not using the angular route provider which I know can cause the controller to execute twice when used in conjunction with .
It appears that Angularjs was not meant to be used in this fashion. Per the angular docs:
You can use Angular to develop both single-page and round-trip apps, but Angular is designed primarily for developing single-page apps...You normally wouldn't want to load Angular with every page change, as would be the case with using Angular in a round-trip app.
To resolve the issue, I moved the angular template as well as the reference to the controller and angular.min.js to the shared _Layout.cshtml file. This partial file loads first and is only reloaded when the entire page is refreshed. Adding angular references and loading controllers in js files referenced in asp.net mvc 3 partials will cause scope replication that can be difficult to detect.
I am starting to learn MVC 3 (Razor engine) and I am having difficulty understanding why my changes don't get applied to page. Basically I have done this: I have imported my DAL and model projects, I have created one controller and one view (in their respective folders) and in the controller Index method I am passing list of products to View
Data.ProductRepository repository = new Data.ProductRepository();
var list = repository.GetProducts(1, true);
return View(list);
And the data is displayed correctly on the page. Now, I want to reformat the columns that are auto generated in the view (I used scaffold list tamplate). The problem is that no matter what I change into this view, the changes are not reflected on the page. I stop the web server, start again, always the same layout is displayed. Even removing columns from table doesn't work. It seems like it is using some cashed version of this page.
Thanks,
Goran
After reinstalling both OS (XP) and IDE, it started working without any proeblems.
I'm just getting started with the Razor view engine. I've upgraded an ASP.NET MVC 2.0 project using the upgrade program here. The upgrade seems to have been successful since I'm able to create new views using the Razor view engine and intellisense works with the # syntax.
I have renamed an existing partial view from "PageView.ascx" to "PageView.cshtml"
However, in my controller when I try to return the partial view like:
return PartialView("PageView", model);
I get a server error saying that the view could not be found. The search paths listed in the error message all end with PageView.ascx or .aspx.
I have created a ASP.NET MVC 3.0 test application from scratch and the scenario above does not generate an error - it finds PageView.cshtml without issue. I've also copied the web.config from the Views folder of the working project to the Views folder of my project that is not working.
Did i miss a configuration step somewhere?
Make sure that you are not doing anything with the ViewEngineCollection in yout Global.asax files.