razor

ID Being Rendered As Null In A Typed Razor View

纵饮孤独 提交于 2020-01-25 09:48:23
问题 This is really weird, for some reason the Id of the ViewModel is being rendered as null inside the view. I debugged the application and checked that the view model is actually being mapped correctly (using AutoMapper) and everything is fine. But when I do @Model.Id, it is rendering as zero, and when I alert the value using jQuery I get "null". So what's going on? <div id="commentBox"> @using (Html.BeginForm("Comment", "Item", new { itemId = Model.Id } )) { <span class="greenText">answer</span

Radio button is checked by default when checked property is false?

 ̄綄美尐妖づ 提交于 2020-01-25 06:11:07
问题 I am trying to generate radio buttons, checking the checked property conditionally if the value exists in database then it should be selected otherwise checked property is false. so initially there are no rows in the database and the checked property is also false for all the radio button but still, it's selected on UI, see below image So don't know whether it's a default behavior or any bug left, below is my code ViewModel public class CompanionProductVersion1ViewModel { [Required

Umbraco 7: Get fields from same property based on current page

。_饼干妹妹 提交于 2020-01-25 04:24:10
问题 In my Content section I have a property editor (Archetype) that allows to set content for the site independently from the content tree. It looks like this: I need to display only the sub categories from one category based on what page I'm currently on. What I have now is: var catItems = Umbraco.Content(1123).categoryItem; //get the Set Content property editor from Content Section foreach (var item in catItems) { foreach (var sub in item.GetValue<ArchetypeModel>("subCatItem")) { <div class=

Pass model to Controller from jquery ajax

馋奶兔 提交于 2020-01-25 03:37:04
问题 How can I pass model to jquery ajax my code id '@Model' is the model on the view.i need to pass this model to controller which accept argument of type login model. $('#reject1').click( function() { var model=@Model; $.ajax({ cache:true, type: "POST", url: "@(Url.Action("Login", "Customer"))", data:'model='+model, success: function() { //Some logic }, complete : function() {} }); return false; }); Above code doesn't work 回答1: For corrected post data you should serialize model data: $('#FormId'

Update label on post using Razor Pages

时间秒杀一切 提交于 2020-01-25 03:05:50
问题 I'm trying to update a label on an http post within a Razor Page. I have a public property called Confirmation as follows: public string Confirmation { get; set; } Then I have my post method: public async Task<IActionResult> OnPostAsync() { //some conditional logic here Confirmation = "Settings saved!"; return Page(); } In my view I have: <label asp-for="Confirmation"></label> However, this renders as: <label for="Confirmation">Confirmation</label> I don't want the word "Confirmation" showing

Can't override bootstrap style with my own stylesheet

空扰寡人 提交于 2020-01-25 00:31:45
问题 ASP MVC RAZOR I try to override the bootstrap default style. I declared my stylesheet as below: /*bootstrap and default style*/ @Styles.Render("~/Content/css"); /*My CSS*/ <link href="@Url.Content("~/css/main.css")" rel="stylesheet" type="text/css" /> @RenderSection("Styles", required: false) In the bundleconfig:(only the default styles) bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/bootstrap.css", "~/Content/site.css" )); But as you can see below my style is overriden by

What am I missing that causes [TempData] decorated property not to retain value from get to post?

半世苍凉 提交于 2020-01-25 00:23:12
问题 My understanding of the TempData attribute in asp.net core is that it marks a model property as needing to persist in value between posts and gets of same page (and possibly wider lifetime than that, but at least that). My issue is that any property I have marked as TempData and set successfully in OnGetAsync has been reset to null by the time user posts back the form. Why might that be? Or have I misunderstood what TempData is supposed to do as an attribute? If I have, what's the best way to

File nesting in solution explorer of ASP.NET Core application

℡╲_俬逩灬. 提交于 2020-01-24 20:55:27
问题 when i created ASP.NET Core 2.0 Razor Page template project, every .cshtml and their .cs file are splitted. I don't know why, before few minutes its working fine but i can't remember what i did. Maybe SDK or settings of Visual Studio. I don't know. Here are screenshot preview of my problem. On the left side is my solution explorer and on the right side is what i want. Thank you for any advice. 回答1: I had the same problem. you need to enable file nesting in the solution explorer. just click

W3C Validation Not working for RazorView

≯℡__Kan透↙ 提交于 2020-01-24 20:22:04
问题 I am using MVC4 project and doing URL rewrite on Server side in RouteConfig and appending .html at the end of url of every page.. www.mysite.com/home.html I have couple of pages and those pages are linked with home page (every think is working find in browser). But when I validate using W3C link checker, I get broken link error message. I really don't know what can be issue. One more thing if I replace .html with .aspx or any other extension it is validated by W3C. I don't know what is issue.

Is there a way to resolve nested interfaces on DTOs in a razor view?

南楼画角 提交于 2020-01-24 20:19:08
问题 We are having an issue with the Razor view engine not resolving nested interfaces. Sample code: public interface IDto { Guid Id {get;set;} } public interface IUserDto: IDto { string Username {get;set;} } //The view @model IUserDto //pukes on this line @Html.DisplayFor(u => u.Id) Should we be using concrete models on our views? Is the Razor view engine not capable of using multiple interfaces per model? 回答1: This was a change in ASP.NET MVC 3 that I already brought to the attention of