asp.net-mvc-5

On Click - Make @Html.DisplayFor an editable text field

纵饮孤独 提交于 2019-12-20 04:23:44
问题 So I am playing with a practice site I made and I want to attempt a feature that will allow me to select any data value in the table, edit it, then save it to the Database. Right now I have an "Edit" button that runs an auto-generated Edit method in the controller and that has its own View for editing and saving, but I want to attempt this edit function within the Index View (or at least pass the data to the edit function within this Index view) Here is how the page looks right now I also

MVC Context Menus Missing

南楼画角 提交于 2019-12-20 04:13:16
问题 I've been following this tutorial http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started on MVC 5. I've got as far as trying to add a controller, and when I right-click on controllers and choose "Add", I don't get some of the options in the picture - e.g. "Controller" or "New Scaffolded Item...". I'm using VS 2013 Professional, and have uninstalled and reinstalled, tried repairing the installation, all to no avail. Has anyone got any ideas? Thanks in advance 来源: https:/

How to display the text in MVC?

走远了吗. 提交于 2019-12-20 03:17:26
问题 I want to display the error message in a textbox in MVC. I used following code for that but its not displaying. userProgram.CompileOutput = "Line number " + CompErr.Line + ", Error Number: " + CompErr.ErrorNumber + ", '" + CompErr.ErrorText + ";" + Environment.NewLine + Environment.NewLine; @Html.EditorFor(up => up.CompileOutput) return View(userProgram); In the above code userProgram returns the value for CompileOutput. But its not displaying in the textbox. 回答1: Just try it, ModelState

MVC5 Identity + multiple context in EntityFramework

拈花ヽ惹草 提交于 2019-12-20 02:52:19
问题 I have a MVC 5 application, which uses the Default Identity authentication. The user profile is part of our model, which means that there are several class which have a foreign key to the UserInfo. There are 2 DbContext, one for the model and another for the UserInfo. public class ApplicationDbContext : IdentityDbContext<UserInfo> { public ApplicationDbContext() : base("Profile") { } } public class UserInfo : IdentityUser { public UserInfo () { LibraryItems = new List<LibraryItem>(); if

Controller without the controller suffix

牧云@^-^@ 提交于 2019-12-20 02:38:07
问题 based on my design requirements, I will like to exclude the suffix 'Controller' from my controllers and replace it with 'Resource'. So that 'FundsController' will become 'FundsResource'. The problem is that I am not able to route to my specified actions by either convention based or attribute routing when I change replace the term 'Controller' and get an error saying that the controller with this name could not be found. How can I satisfy the above mentioned design requirement and also be

Attribute Routing with Multiple Leading Zero Decimals

老子叫甜甜 提交于 2019-12-20 02:29:39
问题 Current ActionResult: [Route("EvaluatorSetup/{evalYear}/{department}")] public ActionResult RoutedEvaluatorSetup(int evalYear, string department) { return EvaluatorSetup((int?)evalYear, department); } I would like to use the url: /EvaluatorSetup/2014/001.3244 where the {department} is a ultimately a string, however, the routing is not picking up {department} as a string. A. I don't know what type MVC is expecting for "001.3244", or what it is picking it up as. B. I want to maintain it as a

Allowing only certain HTML tags as user input

爱⌒轻易说出口 提交于 2019-12-20 02:28:37
问题 My site allows site-users to write blog-posts class BlogPost { [AllowHtml] public string Content; } The site is created using a MVC5 Internet application template and uses bootstrap 3 for it's CSS. So I decided to use http://jhollingworth.github.io/bootstrap-wysihtml5 to take care of all the JavaScript Part of a Rich Text Editor. It works like a charm. But in order to make the POST happen, I had to add the [AllowHtml] attribute as in the code above. So now I'm scared of dangerous stuff that

MVC5 : Attribute Routing Precedence Among Controllers

旧巷老猫 提交于 2019-12-19 18:56:33
问题 I am using the Attribute Routing from MVC5 in my controllers. Question: Is there a way to control attribute routing precedence among controllers? Consider the following [Route("home/{action=index}/{username?}")] public class HomeController : Controller { [Route("home/index/{username?}", Order = 1)] [Route("home/{username?}", Order = 2)] [Route("{username?}", Order = 3)] public ActionResult Index() { // ... bunch of stuff } } Base on the code above, HomeController.Index() action method should

Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater.

最后都变了- 提交于 2019-12-19 12:52:47
问题 The following line does not compile when I put in a Razor View. var extPropLookupNameCompania = $"extension_{SettingsHelper.ClientId.Replace("-", "")}_{"Compania"}"; However in the controller the same line works perfectly fine. Why I cant user string interpolation on the razor views? or Maybe I need to configure something? 回答1: If you are experiencing this error in a .NET Framework 4.5.1 project, upgrading to 4.5.2 solves the problem. 回答2: You have to encapsulate it with braces like this:

ASP.NET MVC 5 Get users from specific Role

亡梦爱人 提交于 2019-12-19 11:57:10
问题 How is it possible to show a List from all users in a specific role. I attach a IdentityRole model to my View with the 'Admin' role assigned to it. So far I only can get the UserId. @model Microsoft.AspNet.Identity.EntityFramework.IdentityRole @Html.DisplayNameFor(model => model.Name) // Shows 'Admin' @foreach (var item in Model.Users) { <tr> <td> @Html.DisplayFor(modelItem => item.UserId) </td> </tr> } A possible solution would be to create a List of the users in the controller and attach