asp.net-mvc-5

Setting TAB Order on MVC View with DropDownListFor()/EditorFor()?

我只是一个虾纸丫 提交于 2019-12-12 06:39:52
问题 Visually speaking, on one of my MVC Views I have about 20 fields in standard vertical order, with the first 8 or so having optional [Create] boxes in same <div> group over on the right. My default tab order currently hits my first dropdown, then goes right to [Create], down to the next, then right, etc. What I would like to do set the TAB order to where it goes straight down my various fields and leave the [Create] boxes as optional for the user (or at the end of the tab order). While there

Html.Action throwing exception: An exception of type 'System.Web.HttpException' occurred in System.Web.dll

核能气质少年 提交于 2019-12-12 06:19:34
问题 I'm getting this error from @Html.Action("getCategory", "Blogs") in the master layout for my blog. The error is: An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code Additional information: Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'. Here is my controller: public ActionResult getCategory() { var categories = _repo.getBlogs().Select(c => new { c.Category }).ToList();

how to render actionlink to view form controller

北城以北 提交于 2019-12-12 06:13:29
问题 ViewBag.htmml = "<li>" + "Html.ActionLink(" + "Home" + ", " + "Dashboard" + ", " + "User" + ")" + "</li>"; Above is my code, using which I am trying render an ActioLink to my view. When the code runs, using the following code, I don't get an actionlink with name as Home, instead i get Html.ActionLink(Home, Dashboard, User) in my <li> part. How to get an ActionLink with what I am trying. @Html.Raw(ViewBag.htmml) 回答1: As @Stephen Muecke have mentioned, HTML needs to be generated in the View,

ViewModel Property Null in Post Action

空扰寡人 提交于 2019-12-12 05:43:29
问题 This is now fixed. A combination of Ish's suggestion below plus adding calls to @HiddenFor in the view resolved the problem. I have an ASP.NET MVC 5 web application where users can mark a defect as resolved. I want to display a list of potentially related defects, with check-boxes that users can tick to indicate that yes, this is the same defect, and should also be marked as resolved. So I have a View Model with a property that is a collection, each member of which contains a defect object

Form fields are null on POST

北城以北 提交于 2019-12-12 05:37:26
问题 I have simple contact form, this is the (view)model: public class ContactForm { [Required] public string Name; [Required] public string Email; [Required] public string Subject; [Required] public string Msg; } Controller: public ActionResult Contact (ContactForm form) { return RedirectToAction("Index"); } View: @model myNamespace.ContactForm ... @using (Html.BeginForm("Contact", "Home", FormMethod.Post)) { @Html.LabelFor(x => x.Name) @Html.TextBoxFor(x => x.Name) @Html.LabelFor(x => x.Email)

Splitting list of objects by DateTime property

Deadly 提交于 2019-12-12 05:26:47
问题 I'm building a booking system for cinemas(of course it's just small project for studies). Here is my Showcase model : public class ShowcaseModel { public string objectId { get; set; } public string MovieId { get; set; } public int Auditorium { get; set; } public DateTime? StartDate { get; set; } } I want to display schedule in "per day" form. To achieve this i get all Showcases where DateTime is greater than today and put them into List< ShowcaseModel >. Now i don't know how to split this

build insert statement error Https has already been declared

不羁的心 提交于 2019-12-12 05:25:54
问题 I have a method which takes multiple images from the UI and stores them in the cache, when this has finished it calls a method which then references the cache pulls the images out and then passes them to the database, at the moment this insert statement is currently doing one at time, so it could be 7 hits to the database for one user. What I'm tying to achieve is something like this, in SQL you would do (multiple items inserted in to the database at once) insert into table1 (First,Last)

ASP.NET MVC 5 EF Cannot add or update a child row: a foreign key constraint fails

故事扮演 提交于 2019-12-12 05:25:22
问题 I've a thread which contains a startpost as part of the thread-content. It also includes a list of replys, which are also posts. class Post { [Key] public int Id{get;set;} public DateTime CreationDate{get;set;} public virtual string Content{get;set;} public int ThreadId{get;set;} public virtual Thread Thread{get;set;} } class Thread { [Key] public int Id{get;set;} public string Title{get;set;} public int FirstPostId{get;set;} public virtual Post FirstPost{get;set;} public List<Post> Replys

cascading drop downs repeatedly populated

六月ゝ 毕业季﹏ 提交于 2019-12-12 05:24:48
问题 I have a three level cascading drop down Customer > Project > Task When I pick a customer I just want to pick that customers projects When I pick a project I just want to pick that projects tasks I have the project > task (level 2 to 3) working OK But when I pick a Customer, it populates Project OK, but then re-populates Task for every project. So it picks the correct tasks but if there are 3 projects above, it will populate those tasks 3 times So when I pick Customer A, it correctly

How to save two entities together using a repository pattern

房东的猫 提交于 2019-12-12 05:09:44
问题 This is my IGenericRepository public interface IGenericRepository<T> { IEnumerable<T> GetAll(); IEnumerable<T> GetMany(Func<T, bool> predicate); void Insert(T obj); void Save(); } and here is its implementation public class GenericRepository<T> : IGenericRepository<T> where T : class { private ApplicationDbContext db; private DbSet<T> table = null; public GenericRepository(ApplicationDbContext db) { this.db = db; table = db.Set<T>(); } public IEnumerable<T> GetAll() { return table.ToList(); }