asp.net-mvc-5

ASP.NET MVC : How to bind dropdown list with nested list type property

ε祈祈猫儿з 提交于 2019-12-12 04:06:07
问题 here is my full code. who will see it then they could understand what i am trying to achieve. after seeing my code if anyone think there is problem in code design then please discuss with rectified version. view model and model code public class MainViewModel { public List<Student> Students { get; set; } public int SelectedState = 0; public int SelectedCity = 0; } public class Student { public int ID = 0; public string Name = ""; public int StateID = 0; public int CityID = 0; public List

retrieve model properties values inside GET method in mvc

不羁岁月 提交于 2019-12-12 03:58:28
问题 I have following GET method , that's a code to a create form public ActionResult Add_Product(string Product_ID) { AddNewProduct sample = new AddNewProduct(); return View(sample); } this is the model class for that public class AddNewProduct { public string Product_ID { get; set; } ... } this is that create form @model project_name.Models.AddNewProduct <h4>Add New Product</h4> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> @Html.ValidationSummary(true, "",

Visual Studio 2015 web deploy always deletes a specific file all the time

…衆ロ難τιáo~ 提交于 2019-12-12 03:56:32
问题 In my Visual Studio 2015 MVC 5 web application, I'm deploying to Azure using publishing profile. In the publishing wizard, under settings, I have selected the Release build configuration and checked the "Remove additional files at destination" under File Publishing options. When I'm done the publishing or even in preview mode it always deleting a view from the destination, instead of updating. It was never being published to the destination via the wizard, so I have FTP the cshtml file using

How to make the DropDownListFor Don't repeat the Database data with the static list?

半城伤御伤魂 提交于 2019-12-12 03:52:45
问题 I have a DropDownListFor a static list of numbers of months if i select the first month 1 and make edit will find the DropDownListFor repeat the first month like this DropDownListFor Code : @Html.DropDownListFor(model=>model.FinancialInfo.FinancialExpiryMonth, (IEnumerable<SelectListItem>)ViewBag.FinancialMonths, (Model.FinancialInfo == null || Model.FinancialInfo.ExpiryDate == null) ? String.Empty : Model.FinancialInfo.ExpiryDate.Value.Month.ToString(), new { @class = "description-text" })

ASP MVC 5 Logged in User can still access Login and Registration Pages?

本小妞迷上赌 提交于 2019-12-12 03:49:18
问题 I have an ASP MVC 5 application and I've noticed that logged in user can still access the registration and login pages. I've also noticed that when a logged in user tries to access a controller action to which they are not authorized, they are redirected to the login page. This is confusing because the user is already logged in. How do I fix this so that unauthorised redirects to some other 401 error page or view. 回答1: On registration/login page, you can redirect logged users : // GET:

Multifield required validation is not working in client side in MVC 5?

拈花ヽ惹草 提交于 2019-12-12 03:37:28
问题 I used to implement multi field required validation using this link MVC3 Validating Multiple Fields As A Single Property But it did not work at my end. Below is the code I used. Javascript $.validator.addMethod('multifield', function (value, element, params) { var properties = params.propertyname.split(','); var isValid = false; var count = 0; for (var i = 0; i < properties.length; i++) { var property = properties[i]; if ($('#' + property).val() != "") { count++; } } if (properties.length ==

Create DropDownList using Iteration Loop

拈花ヽ惹草 提交于 2019-12-12 03:26:18
问题 I will try my best to explain what I am looking for. Let's say for argument's sake that I have a table in my database that has the properties ID , Item , Category ... the table is populated as so: ================================ |ID| |Item | Category | ================================ | 1 | Batman | DC | | 2 | Superman | DC | | 3 | Aquaman | DC | | 4 | Spiderman| Marvel | | 5 | Ironman | Marvel | | 6 | Thor | Marvel | ================================ Now, I want to create a dropdownlist with

DynamoDB avoid duplicate non-key attributes

霸气de小男生 提交于 2019-12-12 03:25:33
问题 I have a user object with these attributes. id (key), name and email And I am trying to make sure these attributes are unique in the DB. How do I prevent a put / create / save operation from succeeding, in case of either of the non-key attributes, email and name , already exists in the DB? I have a table, tblUsers with one key-attribute being the id . I then have two globally secondary indexes, each with also one key-attribute, being the email for the first index-table, and name for the

Custom Routing not working in MVC5

和自甴很熟 提交于 2019-12-12 03:24:45
问题 First of all, I am very new to MVC and this is my first ever project. I am trying to achieve the custom routing URL like the following: http://mywebsite/MDT/Index/ADC00301SB Similar to... http://mywebsite/{Controller}/{Action}/{query} In my RouteConfig.cs, I put the following routes.MapRoute( name: "SearchComputer", url: "{controller}/{action}/{query}", defaults: new { controller = "MDT", action = "Index", query = UrlParameter.Optional } ); In My MDTController.cs, I have the following code

EditorFor & DisplayNameFor inside dl-horizental will be too close to each other

社会主义新天地 提交于 2019-12-12 03:22:58
问题 i have the following code inside my asp.net mvc Razor view, and i am using Bootstrap 3:- <dl class="dl-horizontal"> <dt> @Html.DisplayNameFor(model => model.Name) </dt> <dd> @Html.EditorFor(model => model.Name,new { htmlAttributes = new { @class = "form-control", disabled = "disabled" } }) </dd> <dt> @Html.DisplayNameFor(model => model.Description) </dt> <dd> @Html.TextAreaFor(model => model.Description,new { @class = "form-control", disabled = "disabled" } ) </dd> The result is that all the