tag-helpers

In MVC 6, how to code checkbox list in view and pass the checked values to the controller?

我只是一个虾纸丫 提交于 2019-11-27 02:49:16
问题 Sorry but most of my searches take me to old MVC codes. Any help will be appreciated. In MVC 6 with tag helpers, how do you code a set of checkboxes: Use tag helper for label so clicking it will toggle the checked value Save (Bind?) the checked value to the IsOptionSelected property Pass these checked values back to Controller after clicking Submit ? I was able to display the checkboxes with labels correctly, but I do not know how to pass the checked values back to the controller via the

How to know the selected checkboxes from within the HttpPost Create action method?

a 夏天 提交于 2019-11-27 02:12:36
I have many-to-many relationship between Student and Course . The linking entity set is Enrollment . For the sake of simplicity, they are all defined as follows. Models public class Course { public int Id { get; set; } public string Title { get; set; } public virtual ICollection<Enrollment> Enrollments { get; set; } } public class Enrollment { public int Id { get; set; } public int StudentId { get; set; } public int CourseId { get; set; } public virtual Student Student { get; set; } public virtual Course Course { get; set; } } public class Student { public int Id { get; set; } public string

asp.net conditionally disable a tag helper (textarea)

我与影子孤独终老i 提交于 2019-11-26 16:27:54
问题 I want to enable or disable a textarea depending on a condition that evalueates from the model, and I am using the textarea tag helper. In other words, something like this: <textarea asp-for="Doc" @(Model.MustDisable ? "disabled" : "")></textarea> But I got the following design-time error: The tag helper 'textarea' must not have C# in element's attribute declaration area. Then I tried: <textarea asp-for="Doc" disabled='@(Model.MustDisable ? "disabled" : "")'></textarea> which did not show any

How to know the selected checkboxes from within the HttpPost Create action method?

大城市里の小女人 提交于 2019-11-26 10:00:51
问题 I have many-to-many relationship between Student and Course . The linking entity set is Enrollment . For the sake of simplicity, they are all defined as follows. Models public class Course { public int Id { get; set; } public string Title { get; set; } public virtual ICollection<Enrollment> Enrollments { get; set; } } public class Enrollment { public int Id { get; set; } public int StudentId { get; set; } public int CourseId { get; set; } public virtual Student Student { get; set; } public

Select Tag Helper in ASP.NET Core MVC

邮差的信 提交于 2019-11-25 23:12:42
问题 I need some help with the select tag helper in ASP.NET Core. I have a list of employees that I\'m trying to bind to a select tag helper. My employees are in a List<Employee> EmployeesList and selected value will go into EmployeeId property. My view model looks like this: public class MyViewModel { public int EmployeeId { get; set; } public string Comments { get; set; } public List<Employee> EmployeesList {get; set; } } My employee class looks like this: public class Employee { public int Id {