asp.net-mvc-5

upload 2 different files to 2 different destinations in table and folders

旧时模样 提交于 2019-12-25 07:16:03
问题 I have a form that I'm posting 2 different files that belongs to 2 different values in my Db table. Eg. file1=user image , file2=user company logo . So I need to attach the files url to it's db value with my viewModel , something like this:(Will never work) public ActionResult Create(LectureFormViewModel viewModel) { foreach ((string item in Request.Files).viewModel.Image1) { //Do } foreach ((string item in Request.Files).viewModel.Image2) { //Do } var lecture = new Lecture { Image1 = xxx,

How to properly bind list<object> in the create view of MVC

泪湿孤枕 提交于 2019-12-25 07:15:02
问题 I have a problem similar to the hypothetical below. I have added partial views to another view multiple times but I'm not sure how to get them to bind properly to the view model etc. Also, the validation seems to trigger for every single fooName if a single fooName is wrong. I've added the index to the viewbag as you can see but I'm not really sure how to use it yet. Note:Using MVC5.2 View Models public class Thing { public String thingName { get; set; } public List<Foo> Foos { get; set; } }

Creating buttons dynamically in MVC 5

安稳与你 提交于 2019-12-25 07:09:52
问题 I need to read data from database and create buttons as much as rowcount on a view dynamically on the pageload. Also the button text is going to be taken from database too. i.e; 3 rows in datatable, 3 buttons with their texts from fields in same datatable. I couldn't manage to find an example to create buttons on page load. Most of the "dynamic buttons" examples I came across are triggered by a button click. I suppose I'm going to read the data in a [HttpGet] in the controller.There I can get

ASP.Net MVC: unit test code when working with ValidationAttribute and IClientValidatable

℡╲_俬逩灬. 提交于 2019-12-25 06:59:16
问题 I am bit familiar with ASP.Net MVC but weak in writing unit tests. I read an article about how to write unit test code when working with these classes and interface ValidationAttribute and IClientValidatable . Here is the link to the article: http://www.codeproject.com/Articles/990538/Unit-Testing-Data-Validation-with-MVC I was doing custom validation. The custom validation code as follows public class DateValTest { [Display(Name = "Start Date")] [DataType(DataType.Date), DisplayFormat

Insert created date(now) and created by(username) in asp.net mvc 5 [closed]

前提是你 提交于 2019-12-25 06:49:33
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . Please anybody help me to Insert created date(now) and created by(username) in asp.net5. whenever I create the new record in crud application the above records should be entered automatically in database. regards arun sahani 回答1: It is nothing to do with MVC or any technology. You

Getting checkbox to display if certain item is selected

倖福魔咒の 提交于 2019-12-25 06:37:29
问题 On my Create.cshtml page I have a dropdownlist: <div class="form-group"> @Html.LabelFor(model => model.activityID, "Assignment", htmlAttributes: new { @class = "control-label col-md-2 required" }) <div class="col-md-10"> @Html.DropDownList("activityID", null, "-- Select Activity --", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.activityID, null, new { @class = "text-danger" }) </div> </div> And based on the selection of the user, I need a checkbox

How to inject UserManager & SignInManager

强颜欢笑 提交于 2019-12-25 06:34:04
问题 I am trying to figure out how to inject UserManager and SignInManager. I have installed Ninject in my application and I am using it in the following manner: Please consider this to be a brand new project. Inside Startup.cs I have the following: public partial class Startup { public void Configuration(IAppBuilder app) { ConfigureAuth(app); app.UseNinjectMiddleware(CreateKernel); } private static IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Load(Assembly

Creating an ActionLink and MapRoute that there is a constant name in it

徘徊边缘 提交于 2019-12-25 06:14:25
问题 In my Asp.net MVC 5 (C#) project I want to create some links by @Html.ActionLink or every you know is better like: /Tags/Linq /Tags/SqlServer /Tags/MVC That Tags is constant name and after that in the URL is tag name.For example like ScottGu's Blog In addition I want to pass a parameter such as Id but I don't want to show in the URL. How can I do it? And how should I write a suitable MapRoute for it? Please help me. 回答1: For example (don't forget to write it before default route): routes

Razor view engine location order not honored?

为君一笑 提交于 2019-12-25 05:31:15
问题 I created a RazorViewEngine subclass to redefine where it looks for views. I set PartialViewLocationFormats string array to contain values "~/Views/{1}/{0}.cshtml", "~/Views/{1}/Partial/{0}.cshtml", "~/Views/Shared/{0}.cshtml", The first and last are there by default. The 2nd one is the one I added, so that I could have a "Partial" subfolder in each "Views/ControllerName" folder for partial views used only by views within that controller, rather than adding them to the "Views/Shared" folder.

Custom Role Manager / Provider

我的梦境 提交于 2019-12-25 04:59:15
问题 I am trying to implement a custom role manager in an MVC5 application using the following Custom Role Provider Tutorial. I have created my Custom Role Provider overiding the 2 required functions. namespace Models.Security { public class CustomRoleProvider : RoleProvider { /// logic public override string[] GetRolesForUser(string username) { /// logic public override bool IsUserInRole(string username, string roleName) { I then need to alter my web config to use this new provider... <system.web