asp.net-mvc-5

How do I get an instance of IAppBuilder elsewhere in my ASP.NET MVC 5.2.3 application?

∥☆過路亽.° 提交于 2019-11-29 18:31:17
问题 I need to build an Owin middle-ware object but not from within the Startup class. I need to build it from within anywhere else in my code, so I need a reference to the AppBuilder instance of the application. Is there a way to get that from anywhere else? 回答1: You could simply inject AppBuilder itself to OwinContext . But since Owin context only supports IDisposable object, wrap it in IDisposable object and register it. public class AppBuilderProvider : IDisposable { private IAppBuilder _app;

Want to take difference between single series data and show them on chart in highcharts/highstock

霸气de小男生 提交于 2019-11-29 18:15:10
I am working on asp.net MVC 5 Referring to my question i want to take difference between each two points like this 2-1 3-2 4-3 5-4 and so on and then put them into my series data in chart Bellow is my controller code //Getting data from DB to view in charts SqlCommand Device_Id_command = new SqlCommand("Select Device_ID, Energy_kWh,Power_kW,Voltage_Phase_1,Data_Datetime,Voltage_Phase_2,Voltage_Phase_3,Current_Phase_1,Current_Phase_2,Current_Phase_3 from [ADS_Device_Data] where Device_Serial_Number=@serial_number AND Data_Datetime between'" + time.ToString(format) + "'AND'" + time2.ToString

How to correctly set foreign key constraint in one to many relationship in code first ASP.NET MVC 5 application

蓝咒 提交于 2019-11-29 18:01:20
So I have one document table and a ApplicationUser table. One user can upload multiple documents and a foreign key constraint has been applied accordingly using the code first approach. But the problem is, I am able to save the document without assigning the UserID foreign key id in the Documents table . What am I missing here? Below is my novice attempt. ApplicationUser Model: it's the standard model provided by the framework. Document Model: public class Document { public int Id { get; set; } [StringLength(255)] public string FileName { get; set; } [StringLength(100)] public string

Pushing values to javascript array returning lots of errors

亡梦爱人 提交于 2019-11-29 17:37:20
I'm tring to fill a javascript array with lat longs that I can use to put markers on a map from my model but it's riddled with errors and I'm not sure why. <div id="map"></div> <script> var map, points = []; @foreach (var a in Model) { //Error: The name 'points' does not exist in the current context //Error: ) expected ; expected (at front and end brackets) points.push({ lat: @a.Lat, lng: @a.Lon }); } function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: { lat: -34.397, lng: 150.644 }, zoom: 8 }); //Error: The name 'points' does not exist in the current

Wrong DateFormat with Jquery Datepicker

♀尐吖头ヾ 提交于 2019-11-29 17:29:27
I want to exclude the time part in the DateTime Textbox, but I can't make it work the way I want. This is how I set up the field : @Html.TextBoxFor(m => m.DateFrom, "{0:dd/MM/yyyy}", new { @class = "datefrom" }) @Html.TextBoxFor(m => m.DateTo, "{0:dd/MM/yyyy}", new { @class = "dateto" }) Jquery script: $(function () { $(".datefrom").datepicker({ defaultDate: "+1w", changeMonth: true, numberOfMonths: 1, dateFormat: "dd/mm/yy", onClose: function (selectedDate) { $("#to").datepicker("option", "minDate", selectedDate); } }); $(".dateto").datepicker({ defaultDate: "+1w", changeMonth: true,

Kendo : ComboBox in a grid - Sending additional data of selected combobox to combobox Read()

对着背影说爱祢 提交于 2019-11-29 16:44:38
ASP.NET MVC5 I have a combobox in a grid (InLine Edit): columns.Bound(x=>x.AccountID).EditorTemplateName("MyTemplate") Where MyTemplate is in /Shared There are millions of Accounts. When I try to edit the combo box in a grid and choose a new value, the ID of the Account, not the name, appears. This is because of course the name of the account is not immediately present so in the Read().Data() of the ComboBox.Datasource I need to send additional data ; the AccountID. My ComboBox Template looks like this: .DataSource(source=> source.Read(read => read.Action("ReadAccounts".....) .Data("HERE IS

MVC Identity 2 using FormsAuthenticationTicket

人盡茶涼 提交于 2019-11-29 15:56:30
I am replacing the (HttpContext.Current.User) IPrincipal with a custom version so I can store more information login and the user. I have done this before using the FormsAuthtenticationTicket, but those other ways were based on the Memberhipship and SimpleMembership providers. My question is, can i use the FormsAuthenticationTicket to store the cookie of my ICustomPrincipal with it interfering or breaking in OWIN Identity Pipline? I feel like would i be mixing apples and oranges. example save: var user = userRepository.Users.Where(u => u.Email == viewModel.Email).First();

MVC 5 Increase Max JSON Length in POST Request

戏子无情 提交于 2019-11-29 15:23:54
I am sending a POST request to an MVC controller with a large amount of JSON data in the body and it is throwing the following: ArgumentException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property. Parameter name: input To remedy this, I have tried a number of Web.Config solutions. Namely: <system.web> ... <httpRuntime maxRequestLength="2147483647" /> </system.web> ... <system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength="2147483644"/> </webServices> <

Clientside validation fails for date format dd/mm/yyyy in jQuery Validate

谁都会走 提交于 2019-11-29 15:18:00
问题 I am using jQuery Validate plugin for clientside validation in an MVC 5 application. For the date fields cilentside validations fails when using dd/mm/yyyy format. Is there a way to change the date format in jQuery Validation? 回答1: Adding to Darin's answer. If you happen to already be using the datepicker plugin from JQuery UI then you can use that date parser instead of creating your own: $.validator.methods.date = function (value, element) { return this.optional(element) || $.datepicker

MVC5 ApplicationUser custom properties

会有一股神秘感。 提交于 2019-11-29 15:09:33
问题 I am trying to get to grips with the new Membership system introduced in ASP.NET MVC 5 and I've come across a small issue which I am pretty sure you will be able to help me with. I am going based off this tutorial and have introduced custom properties to ApplicationUser such as Name, Surname, DOB, etc. However, instead of creating the user, I am trying to update the currently logged in one. I am looking at the controller method which is currently used to change password. public async Task