razor

Passing Data to a Layout Page

允我心安 提交于 2020-01-19 12:45:10
问题 I have a layout page that has variables that need to be filled. Example: @ModelType KarateAqua.schoolModel <html> <body> @RenderBody() <div id="footer"> <div class="content"> <div class="bottom_logo"> <a href="/"><span class="inv">@Model.schoolName</span></a> </div> </div> </div> </body> </html> I don't want to populate this in every ActionResult . Is there a way to pass data to a layout page once and do it for all instances? 回答1: OK since you want this to be set once you can make use of a

How to search and load data in database by using a string keyword

天涯浪子 提交于 2020-01-17 14:35:09
问题 This is my ProgramCategories model public class ProgramCategories { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int id { get; set; } public string courseCategory { get; set; } } This is my course information model. public class CourseCategory { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ID { get; set; } [Required(ErrorMessage = "Please Select Field of Study")] [Display(Name = "Field of Study")] public string courseField { get; set; } [Required

RadioButton doesn't get current value from model

橙三吉。 提交于 2020-01-17 08:37:31
问题 My model is IEnumerable<> of RatingSource. public class RatingSource { public int Id; public string Source; public bool IsActive; In the view I want to see 2 columns: Source and radioButton, cheked if IsActive is true. I write: @foreach (var ratingSource in Model) { <tr> <td> @Html.DisplayFor(modelItem => ratingSource.Source) @Html.RadioButton("Active",ratingSource.IsActive) <br /> </td> </tr> } But radioButtons are always unchecked. Where is a mistake? 回答1: have you tried: @Html

Object Moved Here - RedirectToAction

天大地大妈咪最大 提交于 2020-01-17 06:53:21
问题 Again, after tiresome attempts to solve this annoying issue, I am back here. I am experiencing an " Object moved here " on my view in my MVC5 application after some return RedirectToAction("Index", "Roles", model); action on my controller. I have considered solutions from the following links: RedirectToAction and "Object moved to here" error ASP.NET MVC Website: Object Moved to Here https://forums.asp.net/t/1643235.aspx?+Object+moved+to+here+problem but none are applicable to my problem.

Object Moved Here - RedirectToAction

情到浓时终转凉″ 提交于 2020-01-17 06:53:18
问题 Again, after tiresome attempts to solve this annoying issue, I am back here. I am experiencing an " Object moved here " on my view in my MVC5 application after some return RedirectToAction("Index", "Roles", model); action on my controller. I have considered solutions from the following links: RedirectToAction and "Object moved to here" error ASP.NET MVC Website: Object Moved to Here https://forums.asp.net/t/1643235.aspx?+Object+moved+to+here+problem but none are applicable to my problem.

MVC 3 using @model twice

元气小坏坏 提交于 2020-01-17 01:45:11
问题 I would like to using two times @model to get data from another part of my website is it possible? Because now I have got error but if I have only this first @model everything working correct. Look -> MVC 3 - Exception Details: System.InvalidOperationException Error 2 'SportsStore.Entities.Kategorie' does not contain a definition for 'Opis' and no extension method 'Opis' accepting a first argument of type 'SportsStore.Entities.Kategorie' could be found (are you missing a using directive or an

How do I utilize the same variable in both javascript code and asp.net razor mvc code?

a 夏天 提交于 2020-01-17 01:31:04
问题 How do I utilize the same variable in both JavaScript code and ASP.NET MVC Razor code? As you can see from the code below, I created a dropdown and filled it with data. I want the selected item to be utilized in the below div . When the user clicks on an item, what is contained within that div is revealed Then the selected string item is used within the if statement within the div What currently happens is, the selected item isn't globally accessible, causing the issues you can see below.

Post partial view form

微笑、不失礼 提交于 2020-01-16 22:35:14
问题 Can someone help me understand partial views, forms and posting in ASP.NET Core Razor. I have a Search.cshtml partial view located in "~/Client/Search" : @model Web.Pages.Client.SearchModel @using (Html.BeginForm()) { <div> @Html.RadioButtonFor(x => x.searchType, (int)ApplicationCore.Interfaces.SearchType.mobile, new { Name = "SearchType" }) Mobile @Html.RadioButtonFor(x => x.searchType, (int)ApplicationCore.Interfaces.SearchType.phone, new { Name = "SearchType" }) Phone @Html.RadioButtonFor

Filling in the SelectList with a for loop

时间秒杀一切 提交于 2020-01-16 20:07:17
问题 Ok, my drop down used to be made like so: <select id="Level" onchange="showChoice(this.value);"> <option id="0" value="0">Pick a Level</option> @for (int i =1; i <= Model.ExamplesCount; i++ ) { <option id="@i" value="@i">Level @i</option> } </select> because the ExamplesCount number changes per user. But I need to use the Html.ValidationMessageFor() thing, which I can't get to work with this. I need one of two solutions. Can I make Html.ValidationMessageFor() work with this select tag? or if

Filling in the SelectList with a for loop

北战南征 提交于 2020-01-16 20:06:13
问题 Ok, my drop down used to be made like so: <select id="Level" onchange="showChoice(this.value);"> <option id="0" value="0">Pick a Level</option> @for (int i =1; i <= Model.ExamplesCount; i++ ) { <option id="@i" value="@i">Level @i</option> } </select> because the ExamplesCount number changes per user. But I need to use the Html.ValidationMessageFor() thing, which I can't get to work with this. I need one of two solutions. Can I make Html.ValidationMessageFor() work with this select tag? or if