razor

Model binding with complex type

陌路散爱 提交于 2019-12-24 04:25:11
问题 I have made a test controller and view to test complex binding, but I can't seem to make it work. Here is my ViewModel: public class TestViewModel { public SubTest MainTest { get; set; } public List<SubTest> SubTestList { get; set; } } public class SubTest { public string Name { get; set; } public int Id { get; set; } } Here is my View: @model TestViewModel @{ using (Html.BeginForm()) { <h2>Main</h2> <p> @Html.DisplayTextFor(m => m.MainTest.Id) => @Html.DisplayTextFor(m => m.MainTest.Name) <

Ordinary html links in mvc razor

丶灬走出姿态 提交于 2019-12-24 04:23:11
问题 I have an mvc razor app that's humming along nicely, and I just tried to drop in a static html Terms and Conditions page. When I try to link to it from my opt-in cshtml with <a href="~/Views/UserPromotion/TechFundTnC.html">Terms and Conditions</a> It 404s at runtime with "resource cannot be found". It's in the compiled folder. The path and name are correct (I picked it with intellisense, so it knows it's there). The link cshtml page and destination html page are even in the same folder (I've

.NET MVC3 Razor (VB!) Extensions not imported in view?

百般思念 提交于 2019-12-24 04:12:41
问题 My extensions are not imported in my vbhtml view. I seem to be missing something somewhere.. Can anybody help please? The module.vb: Imports System.Runtime.CompilerServices Namespace Areas.Admin.Models.Extensions <Extension()> _ Public Module InputExtensions Public Function SelectHumanGroup(ByVal helper As HtmlHelper, ByVal name As String, Optional ByVal selectedValue As String = "", Optional ByVal htmlAttributes As Object = Nothing) As MvcHtmlString Return helper.DropDownList(name, repo

Using RouteDataRequestCultureProvider in asp net core 3.1

喜夏-厌秋 提交于 2019-12-24 03:46:13
问题 Having upgraded from core 2.2 to 3.1 I cannot get RouteDataRequestCultureProvider working fully. Routing works but razor tag helpers are ignoring the culture and route attributes that use culture. As simple example of custom route attribute: public class StaticPageController : Controller { [Route("{culture:culture}/cookies")] public IActionResult Cookies() => View(); } If I go to the url https://localhost:5002/en/cookies the action is routed to correctly. However in razor, if I use a helper

How can I use Kendo UI with Razor?

烈酒焚心 提交于 2019-12-24 03:39:17
问题 I have downloaded and used Kendo UI with Kendo UI grids, but my source code was very complicated, for several reasons: I've hacked the sort to enable case insensitive sorting. I've observed UI bugs when displaying filter menu, page size selector, filter function menu and DatePicker in the filter menu; I've solved these problems with ugly hacks. On client-side I've refreshed the grid when needed using parameterized posts. On server-side I have created a function which handled the sort, filter,

@Ajax.ActionLink is using GET instead of POST

馋奶兔 提交于 2019-12-24 03:37:17
问题 I am really bummed out that I can't figure out this simple problem even after hours of research: @Ajax.ActionLink("Test", "Test", new AjaxOptions { HttpMethod = "Post" }) <a data-ajax="true" data-ajax-method="Post" href="/Home/Test">Test</a> It's as simple as it can get but it makes a GET request to /Home/Test even though I specified POST. Inside _Layout.cshtml I have <body> @RenderBody() @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/jqueryval") @Scripts.Render("~/bundles

How can I have an ASP Web Form (ASPX) with a Razor MVC Layout?

狂风中的少年 提交于 2019-12-24 03:33:08
问题 I have spent considerable time investigating having an ASP Web Form (ASPX) with a Razor MVC Layout, but have yet to make progress. I need this functionality since Webforms are faster to develop in, and I need to use the WebForm AjaxToolkit. I don't care about passing it a Controller or Model because I can handle all that in the code behind. It seems to boil down to these options: ASP Master Page that builds a Razor Page I based this answer on http://weblogs.asp.net/imranbaloch/a-webform-view

Why does Razor view add “CS$<>8__locals1” prefix to input names when accessing indexer of model assigned to local variable?

半腔热情 提交于 2019-12-24 03:29:50
问题 I'm building a simple ASP.NET MVC 5.2.3.0 view that displays a user name and a checkbox list of roles. You can check or uncheck the checkboxes to control which roles the user is in. Here is my ViewModel: public class EditUserVM { public string Id { get; set; } public string UserName { get; set; } public List<UserRoleVM> Roles { get; set; } } public class UserRoleVM { public string RoleId { get; set; } public string RoleName { get; set; } public bool IsMember { get; set; } } And it's displayed

Creating a DropDownList

时光怂恿深爱的人放手 提交于 2019-12-24 03:24:43
问题 I have a page with a table which list many results. I would like to introduce multiple dropdownlist to filter the results. I would like to know if it could be better to create the List of SelectedItems from code behind and pass it through the viewModel or create the DropDownList directly on the Razor page? The DropDownList will never change on this page. 回答1: Note that You can have many solutions but it is better for the separation of concern to code inside the controller. So you can put your

Url.Action not outputting URL

守給你的承諾、 提交于 2019-12-24 03:21:10
问题 I'm using Url.Action so that I can create more complex HTML links as ActionLink doesn't allow HTML inside them. Example: <a class="uiButton" href="@Url.Action("Areas","Organisations","Manage","Create")" title="New Organisation"> <span class="icon organisations-new">New Organisation</span> </a> However the URL doesn't appear in the href ? Any ideas why ? :/ 回答1: You are using this overload of Url.Action public string Action( string actionName, string controllerName, Object routeValues, string