razor

How to apply bootstrap v4 form input validation classes with the ASP.NET Razor syntax?

和自甴很熟 提交于 2020-06-09 18:22:09
问题 The following code: View:(is-valid) <div class="form-group"> @Html.LabelFor(m => m.Telefone, new { @class = "font-weight-bold" }) @Html.TextBoxFor(m => m.Telefone, new { @class = "form-control is-valid", @placeholder = "Digite seu telefone" }) @Html.ValidationMessageFor(m => m.Telefone, "", new { @class = "text-danger" }) </div> View:(is-invalid) <div class="form-group"> @Html.LabelFor(m => m.Telefone, new { @class = "font-weight-bold" }) @Html.TextBoxFor(m => m.Telefone, new { @class = "form

How to add an item to a list in a ViewModel using Razor and .NET Core?

与世无争的帅哥 提交于 2020-06-09 10:28:27
问题 So here's my situation. Let's say I have a view called TheView.cshtml. TheView.cshtml has a ViewModel called TheViewModel.cs . In TheViewModel.cs , resides a List of an object ( TheObject ) called TheObjectList . I have an editor template for TheObject called TheObject.cshtml . Using this editor template, I can simply display all of the items in the TheObjectList with @Html.EditorFor(model => model.TheObjectList) . However, now I want to dynamically add objects to this list. I have a AJAX

How to add an item to a list in a ViewModel using Razor and .NET Core?

心已入冬 提交于 2020-06-09 10:27:23
问题 So here's my situation. Let's say I have a view called TheView.cshtml. TheView.cshtml has a ViewModel called TheViewModel.cs . In TheViewModel.cs , resides a List of an object ( TheObject ) called TheObjectList . I have an editor template for TheObject called TheObject.cshtml . Using this editor template, I can simply display all of the items in the TheObjectList with @Html.EditorFor(model => model.TheObjectList) . However, now I want to dynamically add objects to this list. I have a AJAX

How to keep script in partial view from loading more than once and causing errors when partial is used more than once in the same page

牧云@^-^@ 提交于 2020-06-09 05:56:06
问题 Working in ASP.NET MVC, I created a partial view which is rendered on the same page 2 times. My problem is the JavaScript is included as many times as the partial view is and JavaScript does not like classes to be redefined. My question is: How do I include the JavaScript in the partial view so it remains modular, but only have it included in the page once? I am not interested in solutions which require including the .js file separately from the content of the partial view, like <script src=

Binding radio buttons in ASP.NET MVC page with razor

孤人 提交于 2020-05-30 08:11:11
问题 I have a page with 4 radio buttons (Exam question and 4 options to choose from). With the code below, I can read the option values after user clicks the button. I have two questions: Why are all radio buttons selected when the page first loads? How to find out which radio button is selected after the post? Thanks! StudentQuestions.cshtml @page "{examId:int?}" @model VerityLearn.WebUI.Pages.Questions.StudentQuestionsModel @{ ViewData["Title"] = "StudentQuestions"; } <div> <form method="post">

How to show the text of a property instead of the ID in Razor MVC 3

亡梦爱人 提交于 2020-05-30 06:05:50
问题 Maybe this is very simple to do but I can't find the good words when I search on stackoverflow or on google. I have a model and this model contains a "Country" property that is a integer. When I am in the Edit view, this property is used this way and it work well. @Html.DropDownListFor(model => model.Country, new SelectList(ViewBag.Countries, "IDCountry", "Name")) In the Details view, I only want to show the name of the country, but I don't know how! Right now, I'm doing this but it only show

How to show the text of a property instead of the ID in Razor MVC 3

偶尔善良 提交于 2020-05-30 06:05:47
问题 Maybe this is very simple to do but I can't find the good words when I search on stackoverflow or on google. I have a model and this model contains a "Country" property that is a integer. When I am in the Edit view, this property is used this way and it work well. @Html.DropDownListFor(model => model.Country, new SelectList(ViewBag.Countries, "IDCountry", "Name")) In the Details view, I only want to show the name of the country, but I don't know how! Right now, I'm doing this but it only show

How to show the text of a property instead of the ID in Razor MVC 3

这一生的挚爱 提交于 2020-05-30 06:04:28
问题 Maybe this is very simple to do but I can't find the good words when I search on stackoverflow or on google. I have a model and this model contains a "Country" property that is a integer. When I am in the Edit view, this property is used this way and it work well. @Html.DropDownListFor(model => model.Country, new SelectList(ViewBag.Countries, "IDCountry", "Name")) In the Details view, I only want to show the name of the country, but I don't know how! Right now, I'm doing this but it only show

XML sitemap remove xmlns from url tag

旧城冷巷雨未停 提交于 2020-05-29 06:48:25
问题 I am using the below lines to generate sitemap but google says there is an error. I know the error but i am unable to figure out how to remove the tag. THe code @using System.Xml.Linq; @{ Layout = null; var urls = new List<string>{ "1", "2", "3" }; XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; var baseurl = "http://www.myurl.in/{0}"; var sitemap = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XElement(ns + "urlset", from url in urls select new XElement("url",

Execute async method on button click in blazor

浪子不回头ぞ 提交于 2020-05-28 13:42:53
问题 I created a "Razor Components" project. I am trying to execute an asynchronous method when pressing a button, but could not figure out the syntax yet. This is my Index.razor : @page "/" @inject GenericRepository<Person> PersonRepository // ... @foreach (var person in persons) { <button onclick="@(() => Delete(person.Id))">❌</button> } @functions { // ... async void Delete(Guid personId) { await this.PersonRepository.Delete(personId); } } When I click the button, nothing happens. I tried