razor

ASP.NET MVC CheckBoxList from model with List Property

有些话、适合烂在心里 提交于 2019-12-17 22:19:38
问题 Apologies if the title is unclear. I'm trying to return my model from a form submit in ASP.NET MVC. My question is nearly the same as this question, only differing in that I don't have a List<Model> but a model like: public Model { string UserName {get; set;} string Password {get; set;} List<Roles> UserRoles {get; set;} } where I need the UserRoles as checkboxes that the admin can select from when creating a new user. My question is, I'm unsure how to use a '@Html.CheckBoxFor' against a list.

asp.net mvc @Html.CheckBoxFor

你离开我真会死。 提交于 2019-12-17 21:57:02
问题 I have checkboxes in my form I added at my model using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace CorePartners_Site2.Models { public class CareerForm { //.... public List<CheckBoxes> EmploymentType { get; set; } } } public class CheckBoxes { public string Text { get; set; } public bool Checked { get; set; } } and added at my form @Html.CheckBoxFor(model => model.EmploymentType, new { id = "employmentType_1" }) @Html.CheckBoxFor(model => model

How to update a second dropdown based on the selection of first dropdown selection?

两盒软妹~` 提交于 2019-12-17 21:23:24
问题 I have two DropDownListFor helpers and the SelectList for the second one depends on the selected value from the first one. So, what I need to do is: when the user chooses a value from the first DropDownListFor helper, the SelectList for the second DropDownListFor helper has to be updated with proper values. How can I update this SelectList with jQuery? 回答1: You need to listen to the change event of your first dropdown, read the selected value and make an ajax request to the server with this

unable to apply Bootstrap classes to my EditorFor

Deadly 提交于 2019-12-17 20:53:38
问题 I am working on an asp.net mvc-5 web application , and i wrote the following :- @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } }) & @Html.EditorFor(model => model.Name, new { @class = "form-control" }) but this will not have any effect on the generated html, but if i changed the EditorFor to be T extboxFor i will get the effect for the form-control class ? can anyone advice on this please ? i read that this is supported only inside asp.net mvc 5.1

ASP.NET MVC 3: Automatically generating view while adding controller (without Entity Framework)

泪湿孤枕 提交于 2019-12-17 20:43:22
问题 I am trying to learn MVC. I want to automatically generate the required view code as and when I add a controller. This is possible if I select the option “Controller with read/write actions and views, using Entity Framework” . However I am not using Entity Framework. How can I achieve the similar behavior without using Entity Framework? And why it is unable to automatically generate the view when I don’t use Entity Framework? Also, is there any good MVC3 tutorial that does not use Entity

MVC4 Razor Custom View Locator

蹲街弑〆低调 提交于 2019-12-17 20:38:50
问题 I'm working on an MVC4 application that is designed to service two domains. Most of our content will be shared across the domains, but sometimes we will need to render different markup (using Razor) depending on which site the request came from. Ideally, I want a convention-based approach that allows me to have a folder structure like this: Views + Domain1 + ControllerName View1 View2 + Domain2 + ControllerName View1 + ControllerName View1 View2 When resolving a view, I would like to check

How to get materializecss checkbox to work with @Html.CheckBoxFor?

假如想象 提交于 2019-12-17 20:37:37
问题 So I'm having an issue trying to implement materializecss' checkbox with @Html.CheckBoxFor. If I input exactly: <input type="checkbox" id="test5" /> <label for="test5">Red</label> it works. But if I try this: @Html.LabelFor(m => m.RememberMe, new { @class = "login-label" }) @Html.CheckBoxFor(m => m.RememberMe, new { @type = "checkbox" }) the checkbox disappears way off the page to the left (the style of the checkbox gets its left set to -99999). Is there any other way I can implement

RedirectToAction with Ajax.Beginform , unexpected results

浪尽此生 提交于 2019-12-17 20:35:34
问题 I have the following view , which contains an Ajax.BeginForm:- @using (Ajax.BeginForm("ChangeDevicesSwitch", "Switch", new AjaxOptions { InsertionMode = InsertionMode.InsertBefore, UpdateTargetId = "result", LoadingElementId = "progress2", HttpMethod= "POST" , OnSuccess = "createsuccess", OnFailure = "createfail" })) //code goes here <p><img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress2" /></p> <div id ="result"></div> and the following Action Method which will be

RazorEngine: cannot use Html.Raw

微笑、不失礼 提交于 2019-12-17 19:57:19
问题 using RazorEngine outside asp.net I'm experiencing this error when I try to write raw html by using @Html.Raw("html string here") : Unable to compile template. The name 'Html' does not exist in the current context Can you help me? Thanks! 回答1: The solution has been found here: https://github.com/Antaris/RazorEngine/issues/34 It's enough to use @(new RawString("html string here")) or @Raw("html string here") instead of @Html.Raw("html string here") . I hope this helps! Bye 回答2: I implemented

how to use text tag in MVC 3 razor

别来无恙 提交于 2019-12-17 19:54:32
问题 i want to use regex on the views i have in MVC 3 page. how i can use when i wrap them with text tag they not work ex: <text> var pattern = @fjkfdkl</text> i not want to put @@ instead of @ on every pattern. well what is the way and rule for using text tag in MVC 回答1: When you wrap something in a text tag your are saying to Razor that "this is text" not code. If you want code you can then do a code block like: <text>@{ var pattern = fjkfdkl; }</text> If you are doing this in some sort of loop