asp.net-mvc-4

How to Use MVC Controller and WebAPI Controller in same project

泪湿孤枕 提交于 2020-06-24 07:13:25
问题 I am trying to use an MVC Controller and a Web API controller in the same project, but I get 404 errors for the Web API. I started the project as an MVC project in VS 2015, but then added the Web API controller, and with the default code it is giving a 404 error. What could be the possible solution? I have tried some solutions on Stack Overflow, but they didn't work. One I tried is the accepted answer from this question: All ASP.NET Web API controllers return 404 Global.asax: protected void

Issue in Enabling CORS for Web API 1, .net 4.0

随声附和 提交于 2020-06-22 13:04:53
问题 I need to enable CORS for my Web API and I can't upgrade to Framework 4.5. I've tried to add the following to my Web.config to see if it worked, but it didn't: <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="Accept,Content-Type,X-Requested-With"/> I am accessing the URL http://localhost:8484/api/values/ from ajax call and getting bellow error XMLHttpRequest cannot load http://localhost:8484/api/values. Response to preflight request doesn't

Issue in Enabling CORS for Web API 1, .net 4.0

允我心安 提交于 2020-06-22 13:03:26
问题 I need to enable CORS for my Web API and I can't upgrade to Framework 4.5. I've tried to add the following to my Web.config to see if it worked, but it didn't: <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="Accept,Content-Type,X-Requested-With"/> I am accessing the URL http://localhost:8484/api/values/ from ajax call and getting bellow error XMLHttpRequest cannot load http://localhost:8484/api/values. Response to preflight request doesn't

HTTP Error 404.15 -Not Found

和自甴很熟 提交于 2020-06-17 03:39:09
问题 The request filtering module is configured to deny a request where the query string is too long. I am having above error, and I have been trying almost everything but no luck My Project is MVC4 on Visual Studio 2013 things I have made sure are correct and tried. There is no [Authorize] Attr on my classes with [AllowAnonymous] Attr. I have added maxQueryStringLength="32768" maxUrlLength="65536" to in my config file I have added --> I have [AllowAnonymous] attr on my log on Actions in my

How to add an item to a list in a ViewModel using Razor and .NET Core?

与世无争的帅哥 提交于 2020-06-09 10:28:27
问题 So here's my situation. Let's say I have a view called TheView.cshtml. TheView.cshtml has a ViewModel called TheViewModel.cs . In TheViewModel.cs , resides a List of an object ( TheObject ) called TheObjectList . I have an editor template for TheObject called TheObject.cshtml . Using this editor template, I can simply display all of the items in the TheObjectList with @Html.EditorFor(model => model.TheObjectList) . However, now I want to dynamically add objects to this list. I have a AJAX

How to add an item to a list in a ViewModel using Razor and .NET Core?

心已入冬 提交于 2020-06-09 10:27:23
问题 So here's my situation. Let's say I have a view called TheView.cshtml. TheView.cshtml has a ViewModel called TheViewModel.cs . In TheViewModel.cs , resides a List of an object ( TheObject ) called TheObjectList . I have an editor template for TheObject called TheObject.cshtml . Using this editor template, I can simply display all of the items in the TheObjectList with @Html.EditorFor(model => model.TheObjectList) . However, now I want to dynamically add objects to this list. I have a AJAX

String as a Model

南楼画角 提交于 2020-05-25 03:38:12
问题 I thought this should have been an easier task : Edit: It seems till this day Asp.Net MVC couldn't provide a neat solution on this case: If you want to pass a simple string as a model and you don't have to define more classes and stuff to do so... Any ideas ?? Pass simple string as a model here I'm trying to have a simple string model. I'm getting this error : "Value cannot be null or empty" / "Parameter name: name" The View : @model string @using (Html.BeginForm()) { <span>Please Enter the

ASP MVC: Upload Image from Database as Full Background CSS

旧时模样 提交于 2020-05-16 04:10:35
问题 I'm still fiddling with MVC and I want to set a full background image which would be retrieved from the database . This is what I used to do in CSS and love to do whenever I need full background: .banana3-sm{ background-image: url('../images/banana3-sm.png'); background-size: contain; background-position: center center; background-repeat: no-repeat; height: 100%; } Below is what I'm using currently because I don't know how to upload the image link from database to CSS. In Controller: model

ASP MVC: Upload Image from Database as Full Background CSS

一个人想着一个人 提交于 2020-05-16 04:10:11
问题 I'm still fiddling with MVC and I want to set a full background image which would be retrieved from the database . This is what I used to do in CSS and love to do whenever I need full background: .banana3-sm{ background-image: url('../images/banana3-sm.png'); background-size: contain; background-position: center center; background-repeat: no-repeat; height: 100%; } Below is what I'm using currently because I don't know how to upload the image link from database to CSS. In Controller: model

Attempting ValidationAttribute in MVC4 that is asynchronous using Async, Task and Await

∥☆過路亽.° 提交于 2020-05-15 03:35:31
问题 I am attempting to write a Validation attribute in MVC4. The purpose is to check for the existence of an application reference (just a string that represents a key I wish to prevent a duplicate for). My data is accessed via WebAPI and because I am using 4.5 I wish to make this asynchronous if possible. I am perhaps not making the best or appropriate usage of async and await but I would like to know how to call my async method from the overridden IsValid method of the inherited Validation