asp.net-mvc-5

Deploying ASP MVC 5 App with IIS 7.5

南楼画角 提交于 2019-12-08 07:32:59
问题 I try to deploy ASP MVC 5 app in virtual directory (without creating new iis application) I use IIS 7.5 I already put <modules runAllManagedModulesForAllRequests="true"/> <directoryBrowse enabled="true" /> in web.config file. But when i go to app url with IE browser it shows me just directory listing like in screenshot below Is there a way to deploy MVC 5 in virtual directory and make it work like usual MVC application? 回答1: You need to convert the virtual directory to application. Right

find UpdateModel Fail Reason

独自空忆成欢 提交于 2019-12-08 07:29:20
In a create view page, all jquery validation pass, when the create object got passed into action, the UpdateModel fails. Is there anyway that I can find which field explicitly fail the update? By watching "e" in Debug Mode? try { UpdateModel(house_info); } catch (Exception e) { throw e; } You can inspect ModelState for errors. The following will give you the list of each property that has an error and the first error associated with the property var errors = ModelState.Keys.Where(k => ModelState[k].Errors.Count > 0) .Select(k => new { propertyName = k, errorMessage = ModelState[k].Errors[0]

ASP.NET MVC razor view, post to a different model from the original model binding?

一曲冷凌霜 提交于 2019-12-08 07:26:55
问题 Well I have a group controller and view in the project, in which the model binding is GroupViewModel. But the group page is complex, and users will be able to make discussion topics. On this group view page, I have forms that allow users to post topics/replies. The model used for these forms can be TopicViewModel or ReplyViewModel, but the original model binding is only for GroupViewModel. It is declared at the beginning of the cshtml page: @model MyProject.ViewModels.GroupBrowseViewModel So

Display Image from Database Using View Models MVC 5

限于喜欢 提交于 2019-12-08 07:00:49
问题 Am working with the built-in template of visual studio 2013 mvc 5. am trying to display images i saved in the database to the index view of the home page. the yellow highlighted sections are where i want to display the images this is my view model for the images i want to display from the database using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace HaveYouSeenMeApp.Models.ViewModels { public class ImageViewModel { public string PetPhotoName { get;

How to put two arrays as key and values of each other in C#?

孤街浪徒 提交于 2019-12-08 06:28:15
问题 I have a form in ASP.Net MVC where contacts can be one or many for example: a project can have one or many contact persons. I created my form it it has a div with two textboxes like blow: <div class="form-group"> <label class="control-label col-md-2">Focal Points</label> <div class="col-md-10"> <div class="input_fields_wrap"> <button class="add_field_button btn">Add More Focal Points</button> <div style="margin:4px;"> Name: <input type="text" name="contact_name[]" /> Phone <input type="text"

AsP.Net MVC 5 how to call a function in view

被刻印的时光 ゝ 提交于 2019-12-08 05:46:09
问题 I have ASP.Net MVC 5 application I want to call a method from view how can I do it? my code: My UsersList function: public ActionResult UsersList() { var User_VM = new UserVM { MyUsers = context.Users.OrderBy(u => u.Email).Include(u => u.Roles).ToList() }; return View(User_VM); } UsersList View: @foreach(var user in Model.MyUsers) { <tr> <td>@user.Email</td> <td> @foreach(var r in user.Roles) { <p> @Html.Action(GetRoleNameById(r.RoleId)) </p> } </td> </tr> } and my function in controller:

Error using $expand with NHibernate and webapi + OData

為{幸葍}努か 提交于 2019-12-08 05:21:28
When you run the query {{odata-url-prefix}}/ArquivosVenda(2)?$expand=Vendas an error is generated: { "odata.error": { "code": "", "message": { "lang": "en-US", "value": "An error has occurred." }, "innererror": { "message": "Argument types do not match", "type": "System.ArgumentException", "stacktrace": " at System.Web.Http.ApiController.<InvokeActionWithExceptionFilters>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices

Stream audio to a webpage from c#

会有一股神秘感。 提交于 2019-12-08 05:16:06
问题 [WebMethod] public void PlayAudio(int id) { using (The_FactoryDBContext db = new The_FactoryDBContext()) { if (db.Words.FirstOrDefault(word => word.wordID == id).engAudio != null) { byte[] bytes = db.Words.FirstOrDefault(word => word.wordID == id).engAudio; MemoryStream ms = new MemoryStream(bytes); System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer(ms); myPlayer.Play(); } } } Apparently in the code above what actually plays the audio is the C# code through the System.Media

EF Code First Fluent API - Cascade Delete

一世执手 提交于 2019-12-08 05:06:37
问题 I have two models: public class User { ..... public virtual UserProfile UserProfile { get; set;} } public class UserProfile { ..... public virtual User User { get; set;} } The User is the master table and the relation is one to one. One user has only one UserProfile. How can I define the relationship between User and UserProfile using EF CodeFirst Fluent API in such a way that when I delete one user from User table the user profile from Userprofile is also deleted? 回答1: Use

User Role/Authorization doesn't work in ASP.NET Identity

耗尽温柔 提交于 2019-12-08 04:50:54
问题 have this (model builder) code on our DbContext.cs base.OnModelCreating(modelBuilder); modelBuilder.Entity<IdentityUserLogin>().HasKey<string>(l => l.UserId); modelBuilder.Entity<IdentityRole>().HasKey<string>(r => r.Id); modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId }); modelBuilder.Entity<ApplicationUser>().ToTable("ApplicationUser"); Everything works fine except for Authorization/User Roles . After checking all tables I noticed that IdentityUserRoles table