asp.net-mvc-5

How can I return a JSON result to a Ajax.BeginForm

懵懂的女人 提交于 2019-12-20 09:53:12
问题 I have got this simple form: @using (Ajax.BeginForm("CreateProductFromAjaxForm","Product" , null, new AjaxOptions() { HttpMethod = "post", OnSuccess = "getresult" }, null)) { @Html.EditorFor(m => m) <hr /> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" class="btn btn-info" value="Next" /> </div> </div> } And, for testing, a simple controller: [HttpPost] public JsonResult CreateProductFromAjaxForm(CreateProductModel model) { if (!ModelState.IsValid) {

Make sure all *.cshtml files are set to be “Content” for Build Action

倖福魔咒の 提交于 2019-12-20 09:47:18
问题 A few times when I copy-paste *.cshtml files, Visual Studio for some reason sets Build Action on these files to be "None": This is impossible to detect when you work locally, because the files are present. But when you deploy through WebDeploy, files marked as "None" on Build Action are not packaged. As a result I get non-working application on the server. Question: is there a way to automatically detect such occurrences and prevent? 回答1: You could extend the .csproj with a small snippet that

Upgrading a project to MVC 5

时光毁灭记忆、已成空白 提交于 2019-12-20 09:32:28
问题 I have been looking for a solution to upgrade a current MVC 4 app that i have to use the new MVC 5 binaries. I cannot find a solution anywhere. Anyone have any ideas? 回答1: Visual Studio 2013 will automatically upgrade a project simply by allowing the Nuget Package Manager to run Updates. Steps: In Visual Studio 2013, open the project and right click on the project name to open the Properties window. Change the Target Framework to at least 4.5. Then, on the project right click on the

Visual Studio 2013 Scaffolding Error

大憨熊 提交于 2019-12-20 09:06:09
问题 I'm using VS 2013 RTM Ultimate, and when I try to add a Controller to my MVC 5 project I get the following error: "There was an error running the selected code generator: 'The Parameter searchFolders does not contain any entries. Provide at least one folder to search files.' None of the scaffolders work basically, all giving the same error... Tried rebuidling / clean etc and still get error. Update Oct 28: Looks like it is a problem with having T4Scaffolding installed. Looks like they are

Custom Identity using MVC5 and OWIN

只愿长相守 提交于 2019-12-20 08:40:21
问题 I trying to add custom properties to the ApplicationUser for a web site using MVC5 and OWIN authentication. I've read https://stackoverflow.com/a/10524305/264607 and I like how it integrates with the base controller for easy access to the new properties. My issue is that when I set the HTTPContext.Current.User property to my new IPrincipal I get a null reference error: [NullReferenceException: Object reference not set to an instance of an object.] System.Web.Security.UrlAuthorizationModule

Identity 2.0 with custom tables

安稳与你 提交于 2019-12-20 08:18:43
问题 I'm new to ASP.NET identity and am still trying to get my head around how it all works. Unfortunately I've found many of the tutorials I've tried are for Identity 1.0, whereas I'm attempting to work with Identity 2.0. The biggest problem I am facing is something I thought would be simple, but has turned out not to be. What I'm trying to do is use an existing database with an existing user table. Currently all I can seem to do is get Identity to create it's own tables to store user data. I don

WebAPI Put returns HTTPResponseMessage null

蓝咒 提交于 2019-12-20 06:39:23
问题 I have a requirement to implement simple edit functionality.I am using webapi service to update my test object. I am calling the below method from the controller post request. This is the controller which calls a metod in test calls wich inturn calls the put service public ActionResult TestEdit(Test test) { if (ModelState.IsValid) { // objTest is returned null HttpResponseMessage objtest = TestDatabaseService.TestEdit(test.testID, test); } } // Method which calls put service testDataService

UserManager updating a user record but creating a new record as well

主宰稳场 提交于 2019-12-20 05:50:54
问题 I'm trying to update 2 records: a user record (bool and custom Object) a custom object (named MoviesDB) I'm using UserManager like so: private UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())); and the code is: using (ApplicationDbContext dbCtx = new ApplicationDbContext()) { // user to update var user = UserManager.Users .ToList() .First(u => u.Id == User.Identity.GetUserId()); // movie to update var movie

How to hide and show div in asp.net mvc 5 using dropdownlist change event

拜拜、爱过 提交于 2019-12-20 05:35:05
问题 I am trying to hide and show div in my mvc 5 project using dropdownlist change event, i have researched, and luckily i found this code online, but it doesn't seem to work for me, i will appreciate if anyone could point at where i am making mistakes. Thanks in advance. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> $(function () { $(document).ready(function () { $("#CountryID").change(function () {

JSTree adding nodes to child nodes

无人久伴 提交于 2019-12-20 04:59:10
问题 I am using JSTree with a MVC project and I am trying to add child nodes to the tree, however I am getting a null refference error Object reference not set to an instance of an object on the line subGroupNode.children.Add(itemNode); I guess this is because the subGroupNode.Children is empty. how can it be when the child is created in the previous foreach loop. public JsonResult GetJsTree3Data() { var marketGroups = new List<JsTree3Node>(); // Create our root node and ensure it is opened var