asp.net-core-mvc

Data Annotation for currency format not working

南楼画角 提交于 2019-12-02 11:59:43
In my ASP.NET MVC Core web project on VS2015 , the following model is displaying data as, e.g., 15481 instead of $15,481 even though I'm using [DisplayFormat] below: Models : public class State { [Key] public int StateId { get; set; } [Column(TypeName ="varchar(40)")] public string StateName { get; set; } [Column(TypeName = "char(2)")] public string StateCode { get; set; } } public class Sales { [Key] public int SalesId { get; set; } public int? FiscalYear { get; set; } [DisplayFormat(DataFormatString = "{(0:C0)}")] public float? SaleAmount { get; set; } public int StateId { get; set; } public

ModelState.IsValid is false prior to validation

随声附和 提交于 2019-12-02 11:24:18
We wrote a custom model binder that overrides the CreateModel method of the ComplexTypeModelBinder so that we can have injection into our ViewModels instead of having to pass the injected clients and repos to our model from the controller . For example, for a model like this: public class ThingViewModel { public ThingViewModel (IThingRepo thingRepo) {} } In our controller we can do: public class ThingController : Controller { public IActionResult Index(ThingViewModel model) => View(model); } And this works pretty well, here's the override part of the custom model binder : protected override

Redirect to action after finishing background task queue

倖福魔咒の 提交于 2019-12-02 11:20:27
I'm working on a .Net core solution that takes backup of storage files from another microservice and because this process takes too long time, we decided to build this routine under a background task.By following this link: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-2.1 I have implemented the background by using Queued background tasks like the following : public interface IBackgroundTaskQueue { void QueueBackgroundWorkItem(Func<CancellationToken, Task> workItem); Task<Func<CancellationToken, Task>> DequeueAsync( CancellationToken

TagHelpers doesn't get invoked after moving them to a different project

↘锁芯ラ 提交于 2019-12-02 09:02:26
I'm having some issues with asp.net core not finding and invoking my tag helpers. After I moved the taghelpers from a seperate assembly ( LC.Tools.Utility.TagHelpers ) to LC.Tools.Utility it doesnt seem like they get discovered even though the namespace is the same as before. Sample cshtml : <lc:css src="styles.min.css" /> <lc:css src="styles.bootstrap.min.css" /> <lc:css src="styles._layout.min.css" /> When looking at the source for the page the tags are exactly the same. _ViewImports.cshtml : @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, LC.Smokers.Albino.TagHelpers

Read ControllerBase.User in constructor

非 Y 不嫁゛ 提交于 2019-12-02 08:51:53
问题 I'd like to have a base controller that should set auth variables for every controller action: _claimsIdentity = User.Identity as ClaimsIdentity; _userId = claimsIdentity.FindFirst("ID")?.Value; Unfortunately ControllerBase.User is null in the constructor and there's no Initialize method on ControllerBase to override as suggested here. How can I make a base controller with these values already set for every action? 回答1: The controller is initialized earlier in the pipeline before the User

Listbox for MVC 6 EF 7 Property not Populating

为君一笑 提交于 2019-12-02 08:48:00
问题 I've been trying for a while now to get a list box to populate and I can't seem to figure it out. I've studied entity framework 7 documentation pretty extensively but I'm still new to it. There aren't a lot of tutorials out there for MVC6/EF7 yet so its been hard to know what the best practice is for associating one entity class with an instance of another. Please excuse the length of the question, I'm just trying to be thorough. I'm using entity framework 7, asp.net 5 and MVC 6. Steps To

Bootstrap Datepicker: Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?)

别来无恙 提交于 2019-12-02 08:44:51
I am a newbie here. I have gone through similar questions here but none of them helped. I have the following in my ViewModel : public DateTime FromDate { get; set; } public DateTime ToDate { get; set; } When I run the code, in the View after GET Method , I am getting the default dates as: 01/01/0001 , in other words, null /default value. I searched online and found out that I need to make these fields nullable . Therefore, I changed the above code to: public DateTime? FromDate { get; set; } public DateTime? ToDate { get; set; } Upon changing, I am getting the following error for both FromDate

Cannot use table 'AspNetUsers' in schema '' for entity 'AspNetUsers' since it is being used for another entity

女生的网名这么多〃 提交于 2019-12-02 08:00:29
问题 We are trying to add Identity 3 to our existing Customers app by extending AspNetUsers public class ApplicationUser : IdentityUser { public string BusinessName { get; set; } public string ContactName { get; set; } public string CountryCode { get; set; } public virtual Countries Country { get; set; } public string AddressLabel { get; set; } public string Phone { get; set; } public DateTime? FollowUp { get; set; } public bool MailingList { get; set; } public int SubscriptionId { get; set; }

Listbox for MVC 6 EF 7 Property not Populating

送分小仙女□ 提交于 2019-12-02 07:00:00
I've been trying for a while now to get a list box to populate and I can't seem to figure it out. I've studied entity framework 7 documentation pretty extensively but I'm still new to it. There aren't a lot of tutorials out there for MVC6/EF7 yet so its been hard to know what the best practice is for associating one entity class with an instance of another. Please excuse the length of the question, I'm just trying to be thorough. I'm using entity framework 7, asp.net 5 and MVC 6. Steps To Reproduce Issue Create a new ASP.Net Web Application → Name of project: ListBox.Web → Name of solution

Read ControllerBase.User in constructor

隐身守侯 提交于 2019-12-02 06:55:38
I'd like to have a base controller that should set auth variables for every controller action: _claimsIdentity = User.Identity as ClaimsIdentity; _userId = claimsIdentity.FindFirst("ID")?.Value; Unfortunately ControllerBase.User is null in the constructor and there's no Initialize method on ControllerBase to override as suggested here . How can I make a base controller with these values already set for every action? Kirk Larkin The controller is initialized earlier in the pipeline before the User property has been set. This means that it will be null if you try to access it in the constructor.