razor

Using a javascript variable within Razor

不问归期 提交于 2021-01-29 07:30:37
问题 I am aware that Razor is server side and Javascript client side. I am trying to workaround this. Here's what I wanted: RAZOR: if (count > 0) { t.Add().Text("Yeah") ... ... } } But that count is defined at the beginning of the View, like this: @{ int count = 2; } But I can't define it like that: the value for count is on a javascript variable, set on document.ready . Then, I want to use it in the Razor if condition. Is it possible to workaround this? 回答1: Simply No , The reason is same server

Razor Partial View Error

为君一笑 提交于 2021-01-29 07:04:02
问题 I'm following the example website being built in Pro ASP.NET MVC 2 Framework (but using Razor instead of ASPX as I go along). However, I've hit a snag with a partial view. I'm getting the following error: The model item passed into the dictionary is of type 'SportsStore.WebUI.Models.ProductsListViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[SportsStore.WebUI.Models.NavLink]'. Here are the relevant files: _Layout.cshtml: <!DOCTYPE html>

Download a file with ASP.NET Core Razor page

落爺英雄遲暮 提交于 2021-01-29 05:32:36
问题 Clarification edit I have created a NEW project trying to convert my original MVC project to now only use Razor pages. My original solution is Here. It took me a while to get the conversion done to display a list of the documents but I have that completed now. I've been working on trying to get the file to download but it keeps telling me that the file doesn't exist, even though it's listed. ERROR message No webpage was found for the web address: https://localhost:5001/FileShare/DownloadStub

How to show checked radio button in Razor edit view Asp net core mvc

谁说胖子不能爱 提交于 2021-01-28 23:31:42
问题 Despite of Asp net core code in Razor view: @model List<SelectListItem> <form asp-controller="Manage" asp-action="Change" method="post"> @foreach (SelectListItem item in Model) { <br /> <input asp-for="@item.Value" type="radio" value="@item.Value" /> @(item.Value + " - " + item.Text) } <br /> <input type="submit" value="OK" /> </form> all radio buttons are checked in browser -> view source <input type="radio" value="1001" checked="checked" id="item_Value" name="item.Value" /> 1001 - Vilnius

How to show checked radio button in Razor edit view Asp net core mvc

旧巷老猫 提交于 2021-01-28 23:13:35
问题 Despite of Asp net core code in Razor view: @model List<SelectListItem> <form asp-controller="Manage" asp-action="Change" method="post"> @foreach (SelectListItem item in Model) { <br /> <input asp-for="@item.Value" type="radio" value="@item.Value" /> @(item.Value + " - " + item.Text) } <br /> <input type="submit" value="OK" /> </form> all radio buttons are checked in browser -> view source <input type="radio" value="1001" checked="checked" id="item_Value" name="item.Value" /> 1001 - Vilnius

ASP.NET MVC Razor set style attribute in foreach

我的梦境 提交于 2021-01-28 18:21:00
问题 I want to set the width of a div via the style Attribute (to use the div as a bootstrap progress bar. I want to do this in a foreach loop @foreach (var item in Items) { <tr> <td>@item.Name</td> <td> <div class="progress"> <div class="progress-bar" role="progressbar" aria-valuenow="@item.PercentageCompleted" aria-valuemin="0" aria-valuemax="100" style="width: @item.PercentageCompleted;"> </div> </div> </td> </tr> } ` What happens is that the style attribute is empty. Is there a way to achieve

How to do not repeat a razor code in an ASP.NET MVC “edit” view for each model property?

孤街浪徒 提交于 2021-01-28 10:11:36
问题 If you use ASP.NET MVC, then the following code must be familiar to you: <div class="row"> <div class="form-sm-4"> @Html.LabelFor(m => m.att) </div> <div class="form-sm-8"> @Html.EditorFor(m => m.att, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(m => m.att) </div> </div> This is a basic input group set with label, input and validation message. Today I'm facing a POCO class with dozens of attributes. I mean It has N number of properties in model class.

How to do not repeat a razor code in an ASP.NET MVC “edit” view for each model property?

删除回忆录丶 提交于 2021-01-28 10:01:57
问题 If you use ASP.NET MVC, then the following code must be familiar to you: <div class="row"> <div class="form-sm-4"> @Html.LabelFor(m => m.att) </div> <div class="form-sm-8"> @Html.EditorFor(m => m.att, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(m => m.att) </div> </div> This is a basic input group set with label, input and validation message. Today I'm facing a POCO class with dozens of attributes. I mean It has N number of properties in model class.

How to use PaginatedList with ViewModel using MVC

ε祈祈猫儿з 提交于 2021-01-28 08:01:41
问题 I am trying to find a solution for creating a PaginatedList with a ViewModel. Tutorial (using only an ordinary model) https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/sort-filter-page?view=aspnetcore-2.1 Similar problem How do I paginate through a ViewModel in MVC CORE? MVC/Entity framework core using ViewModel with paging My Code Controller public async Task<IActionResult> Index(string sortOrder, string currentFilter, string searchString, int? page) { ViewBag.NameSortParm = String

Passing button value from view to controller aspnet 5

孤人 提交于 2021-01-28 07:33:09
问题 I'm building a aspnet mvc6 application where I want to pass values from View to controller. My view has multiple buttons having IDs and I want to pass the ID of the button which is clicked to my controller using my viewmodel. Controller: public class HomeController : Controller { private SampleDbContext _context; private HomeViewModel _viewmodel; public HomeController(SampleDbContext context, HomeViewModel model) { _viewmodel = model; _context = context; } public IActionResult Index() {