asp.net-mvc-5

How to format date in asp.net mvc 5

强颜欢笑 提交于 2019-12-11 07:44:47
问题 I am trying to format a date in asp.net MVC 5 by setting in a model class but not getting the desired result. Please view the date below: 10/10/2010 12:00:00 AM I want to change the above date in the following format:- OCT-10-2014 Please view my model class below [DisplayFormat(DataFormatString = "{0:MMM-dd-yyyy}", ApplyFormatInEditMode = true)] [Required(ErrorMessage = "Date is required")] public DateTime? DateOfBirth { get; set; } The above code is not formatting in the required format .

ModelBindingContext.ValueProvider.GetValue(key) always returns null

♀尐吖头ヾ 提交于 2019-12-11 07:29:25
问题 I'm using AngularJS to manipulate a fairly complex parent object with children that need to behave quite differently server-side. Based on this answer, which appears pretty solid, I've created the test case below. The issue I'm running into is that whenever I enter the CreateModel function, any call to bindingContext.ValueProvider.GetValue(key) returns null. I've checked all values in the debugger. The object type appears to be loaded, but no values have yet been bound. My Models: public

How to show a pop up or warning to user if the DB Row is going to be overwritten in ASP.NET MVC 5

天大地大妈咪最大 提交于 2019-12-11 07:28:23
问题 Requirement: I have a referral form, where user can fill in the details to apply for a job. Now, As per my requirement, if a user wants to reapply for the same job, he can do so, multiple number of times (humor me on this). So, If I detect that user has already applied for the job before then I need to update the old referral request, if not then create a new request. Current Behaviour: I have successfully written the logic to overwrite the existing value (if user had already applied before).

Visual Studio 2013 - Debugging MVC code with ViewBag properties deathly slow and unusable

浪尽此生 提交于 2019-12-11 07:26:09
问题 I'm trying out the latest Visual Studio, but debugging the most elementary MVC application with ViewBag dynamic variables gives me a lot of headache. I'm running Visual Studio 2013 under 32-bit Windows 8 operating system with clean install and every available update applied. I created new ASP.NET Web Application (.NET Framework 4.5 - New Solution) with folders and core references for MVC after which I added sample Home controller with some element code: dynamic d1 = 1; dynamic d2 = 2;

Syndication keys missing MVC

心不动则不痛 提交于 2019-12-11 07:08:58
问题 Really need some help with this one.... I'm trying to get my MVC app to use the Syndication library for the RSS feed reader part of my program and got stuck while trying to enable migrations saying that: RssProject.Models.SyndicationPerson: : EntityType 'SyndicationPerson' has no key defined. Define the key for this EntityType. RssProject.Models.SyndicationElementExtension: : EntityType 'SyndicationElementExtension' has no key defined. Define the key for this EntityType. RssProject.Models

How to configure one to zero and one to one relationship in fluent api with different PK and FK

落花浮王杯 提交于 2019-12-11 07:03:13
问题 I am a beginner and learning fluent API from tutorials. I read the some of the already given SO solution about 1-0, 1-* but I could not understand them properly. I simply want to use fluent API to set up One to One and One to Zero Relationship provided no convention followed. House and Room (terrible example) Requirement: 1. One House can have zero room or ONE room MAX. 2. One Room must be inside a house. 3. If a room is deleted House SHOULD NOT Get Deleted 4. If a House is getting deleted

The entity type ApplicationUser is not part of the model for the current context, DB First with custom user store

时间秒杀一切 提交于 2019-12-11 06:57:10
问题 So I'm building an application on top of an existing database to which I have limited rights to change (the idea is to make as few changes to the DB schema as possible). This is an MVC 5 application attempting to use the Identity system with a custom user store to a MySQL database. Problem: I'm getting the following exception when attempting to register a user via the auto-generated AccountController in the register method: IdentityResult result = await UserManager.CreateAsync(user, model

AntiForgeryToken Error in ASP.NET MVC 5 app

走远了吗. 提交于 2019-12-11 06:54:08
问题 I get this error - even though the AntiForgeryToken IS definitely in my view, inside a form tag: The required anti-forgery cookie "__RequestVerificationToken_L0NpdTpLaW5nMTZNVkM10" is not present. Controller /// <summary> /// Delete /// </summary> public ActionResult Delete(int Id) { // Get place from Id var poll = PollRepo.Select(Id); if (poll == null) return HttpNotFound(); return View(poll); } /// <summary> /// Confirm Delete /// </summary> [HttpPost, ActionName("Delete")]

MVC 5 asp.net, viewbag from controller to view is not working

倾然丶 夕夏残阳落幕 提交于 2019-12-11 06:43:45
问题 this is the controller public ActionResult Test() { @ViewBag.TheMessageIs = "this is the message"; return RedirectToAction("Details", new { id = theId}); } on the view of Action Named Details I will check if it has the ViewBag to show and show it: @{ if(ViewBag.TheMessageIs != null){ @ViewBag.TheMessageIs } } but here the redirection is working fine to the page, it's not show the message I have stored in ViewBag.TheMessageIs thanks 回答1: public ActionResult Test() { TempData["shortMessage"] =

jQuery getJSON with .NET MVC not working

放肆的年华 提交于 2019-12-11 06:38:10
问题 I have setup a getJSON call when page loads in my .NET MVC app like this: $(document).ready(function(){ $.getJSON("/Administrator/GetAllUsers", function (res) { // getting internal server error here... }); }); And the action looks like this: [HttpGet] [ActionName("GetAllUsers")] public string GetAllUsers() { return new JavaScriptSerializer().Serialize(ctx.zsp_select_allusers().ToList()); } I'm getting this error: 500 (Internal Server Error) What am I doing wrong here??? 回答1: In MVC, json