asp.net-mvc

How can I return 500 error in JSON format in ASP.NET MVC?

扶醉桌前 提交于 2021-02-07 05:27:05
问题 When ASP.NET MVC throws an exception, it returns a 500 error with response type text/html - which, of course, is invalid JSON. I want to respond to an Ajax request expecting JSON with an error I can receive and display to the user. Is it possible to return JSON with an HTTP status code of 500? When the problem is a missing parameter, the 500 error occurs before the controller is even called - so a controller solution might not work. For example, leaving a required parameter out in a call to

Securing Connection String In Asp.net MVC

不羁的心 提交于 2021-02-07 04:32:25
问题 I have An Asp.net MVC Application With VS.Net2013 in my webconfige file i have connection string Section like this: <connectionStrings> <add name="ConnectStrNL" connectionString="server=192.168.0.71\ins1;database=FNHProvider;MultipleActiveResultSets=true;persist security info=True;User ID=general;Password=123;" /> <add name="connectionStringGeneral" connectionString="server=192.168.0.254;database=NFS;MultipleActiveResultSets=true;persist security info=True;User ID=General;Password=*******;" /

Send ASP.NET MVC HttpContext to Web Api HttpContext

霸气de小男生 提交于 2021-02-07 04:31:25
问题 I'm trying to upload a file and I'd like to pass the current MVC HttpContext.Current.Request.Files to a Web API. I tried to pass the HttpFileCollectionBase as parameter to pass it to the API but it's always null. Controller public object UploadAttachment(string param1, int param2, HttpFileCollectionBase files) { string _url = _restUrl + param1+ "/Folders/" + param2+ "/UploadAttachment"; HttpResponseMessage _response = SendJsonRequest(_url, HttpMethod.Post, files); var ret =

What is difference between Model and ViewModel in asp.net core mvc? [duplicate]

我与影子孤独终老i 提交于 2021-02-07 04:18:44
问题 This question already has answers here : What is ViewModel in MVC? (15 answers) Closed 3 years ago . I have a Account class for account models. public class Account { [Key] public Int64 UID { get; set; } [Required] public string ID { get; set; } [Required] public string PassWord { get; set; } [Required] public string UserName { get; set; } } My project is not a code first project and this is a model class for database 'Account'. But I use only two properties in login view, string ID and

What is difference between Model and ViewModel in asp.net core mvc? [duplicate]

一世执手 提交于 2021-02-07 04:18:19
问题 This question already has answers here : What is ViewModel in MVC? (15 answers) Closed 3 years ago . I have a Account class for account models. public class Account { [Key] public Int64 UID { get; set; } [Required] public string ID { get; set; } [Required] public string PassWord { get; set; } [Required] public string UserName { get; set; } } My project is not a code first project and this is a model class for database 'Account'. But I use only two properties in login view, string ID and

Accessing WebAPI 2 json with DataTables.NET ajax call in MVC application

血红的双手。 提交于 2021-02-07 04:10:54
问题 I have been trying to get DataTables.NET to play nicely with a WebAPI RESTFul service I built and the json being returned does not seem to fit what DataTables is looking for. I have tried the various "server processing" examples along with a few examples I found on the internet like this one, but I don't want to make the WebAPI call dynamic. I want the API to be self documenting so that other applications and other developers can easily also use the API. So far, here is what I have. The JSON

Route Id overrides Model.Id

佐手、 提交于 2021-02-07 03:54:34
问题 I have a route like this: Conference/Committees/1 And within that page, it cycles through the Committees for a Conference (where the Conference Id = 1). I have a partial view that renders an edit style page for a selected committee, with a route like this: Conference/Committees/1?committeeId=2 In debug, the model data is correct, and the Committee has an Id = 2. However, when I use the following Razor statement: @Html.HiddenFor(model => model.Id) with the following model: @model munhq.Models

Route Id overrides Model.Id

筅森魡賤 提交于 2021-02-07 03:48:00
问题 I have a route like this: Conference/Committees/1 And within that page, it cycles through the Committees for a Conference (where the Conference Id = 1). I have a partial view that renders an edit style page for a selected committee, with a route like this: Conference/Committees/1?committeeId=2 In debug, the model data is correct, and the Committee has an Id = 2. However, when I use the following Razor statement: @Html.HiddenFor(model => model.Id) with the following model: @model munhq.Models

Route Id overrides Model.Id

久未见 提交于 2021-02-07 03:46:35
问题 I have a route like this: Conference/Committees/1 And within that page, it cycles through the Committees for a Conference (where the Conference Id = 1). I have a partial view that renders an edit style page for a selected committee, with a route like this: Conference/Committees/1?committeeId=2 In debug, the model data is correct, and the Committee has an Id = 2. However, when I use the following Razor statement: @Html.HiddenFor(model => model.Id) with the following model: @model munhq.Models

Route Id overrides Model.Id

杀马特。学长 韩版系。学妹 提交于 2021-02-07 03:45:40
问题 I have a route like this: Conference/Committees/1 And within that page, it cycles through the Committees for a Conference (where the Conference Id = 1). I have a partial view that renders an edit style page for a selected committee, with a route like this: Conference/Committees/1?committeeId=2 In debug, the model data is correct, and the Committee has an Id = 2. However, when I use the following Razor statement: @Html.HiddenFor(model => model.Id) with the following model: @model munhq.Models