Questions tagged [razor]

11419 questions
1

votes
1

answer
433

Views

ASP.Net Core 2 - How can I get Visual Studio Code to detect Razor Pages?

In Asp.net core 2, they introduced razor pages. Using visual studio code if I create a 'Pages' folder in the root of the solution and then add a new item 'Greeting.cshtml', then add an @page directive at the top followed by the content I want to display, I don't see anything when I navigate to http:...
User123
1

votes
0

answer
698

Views

ASP.NET MVC Razor Sections and Partials

I'm relatively new to ASP.NET MVC and Razor. We've been modifying and developing based on existing code. Thus, there is a lot of duplication (ugh!). So I started looking at Partial pages and learning about Sections. I followed these tutorials but I'm still a bit confused. ASP.NET MVC 3: Layouts...
Patricia
0

votes
0

answer
4

Views

What are the correct tags for ASP.NET Core Model Binding to dynamic elements created by JavaScript

I'm using client-side JS to create form elements so the values are sent on a POST. I have a simple C# object as follows: public class GroupModel { public string GroupId { get; set; } public string GroupName { get; set; } } In my Razor page's controller code I'm using model binding: [BindProperty] pu...
Jason Shave
1

votes
2

answer
44

Views

DropdownList value doesnt add to database

I can display the values from my database both in a dropdownlist and where the value is needed. But I can't get the value from the dropdownlist to my database while creating something. it's getting null. I've tried some solutions from s.o.f but they didnt't work. Models 1: public class Kategori { [K...
LunaLuna
1

votes
0

answer
200

Views

Required field validation with label name in MVC asp.net

Is there anyway to show label as required when validating a form? I'm asking this because I have this translated labels in my form and it would be easier if I can show those labels when user missed one instead of standard 'Required' text(which is not translated). I want to replace [Required(ErrorMes...
H35am
1

votes
1

answer
113

Views

Editing only part of object in view but pass whole obj to ActionListener

I have a form with a submit button that should pass through the item to the actionlistener. I thought it might be similar to the question in @Html.HiddenFor does not work on Lists in ASP.NET MVC but none of the answers seem to work. You can even see my for-loop taken from one of the answers in there...
Corné
1

votes
0

answer
279

Views

React component doesn't unmount

I have a simple react component inside a cshtml (Razor) page using the following syntax: And I have a react index file which mounts a component inside that div using: ReactDOM.render(, document.getElementById('reactContainer')); The problem I am having is that as I navigate to and from the cshtml pa...
Ruskin
1

votes
1

answer
377

Views

ASP.NET razor incorrectly works multiselect dropdownlist

There is a drop-down list with a multiselect I prepare a list, so that some values were selected by default List allUsers = await db.Users.Select(u => u.UserName).ToListAsync(); List usersAssignedTo = await db.MasterAssigmentTables.Where(mat => mat.TableId == id && mat.TableName == typeof(TestCaseDe...
Dennis Spade
1

votes
1

answer
85

Views

ASP.NET MVC mix Razor and JavaScript

How can we pass a JavaScript variable to Razor code? Here I have a simple tabs @MEDONET.Language.Doctor.Texts.About @MEDONET.Language.Doctor.Texts.Info @MEDONET.Language.Doctor.Texts.Diplomas @MEDONET.Language.Common.Texts.Licenses @MEDONET.Language.Doctor.Texts.Summary @MEDONET.Language.Common.Tex...
1

votes
3

answer
272

Views

How to TransferRequest to cshtml file?

I am looking at the ASP.NET MVC4 application which is calling Server.TransferRequest('Error.cshtml') while executing one of the requests where Foo.cshtml is a view page residing in the root folder of the application. Everything is working fine on our old server, but once I deployed this app to our n...
Michal Hosala
1

votes
1

answer
1.3k

Views

Bootstrap Multiselect in ASP.Net Core Razor Page does not show the drop-down when clicked

I am unable to get the bootstrap multiselect drop-down to work in my View. I simply get the button pictured here . However, clicking on it does not trigger the drop-down to appear. Below is my code snippet and the css/js files I'm including. I did not catch any errors in the browser dev tools. Am I...
user1860688
1

votes
0

answer
316

Views

To bold “selected” text in textarea with javascript/jquery

I have a code which bold the complete text present in textarea but i want to Bold only selected text to be bold present in text area. Note that i don't want the text to be in Div tags. I want to do the same with text area only. here is my code: This is some text in our textarea and here is my javasc...
Yash Katiyar
1

votes
0

answer
24

Views

Kendo Grid Binding with Razor

I setup a function used to save the grid's state along with its options to a database whenever something is modified. Every user will have their own respective settings. The saving and loading functions of the grip options are functional, however upon page loading, the loadGridState function is cal...
glowstarraw
1

votes
1

answer
56

Views

output html in multiple lines

I'm using Skybrud Social to get Instagram feeds. The caption I got from the feed is something like below: Line 1 Line 2 Line 3 When I output it to html it will be Line 1 Line 2 Line 3 How do I make it so that it display just like the first? s = CurrentPage; Skybrud.Social.Umbraco.Instagram.PropertyE...
1

votes
2

answer
813

Views

How to write razor query to display two fields side by side?

I am dynamically generating the fields using a foreach loop. I have several conditions on rendering those fields. There is one condition where on it being true, there are two fields that should be rendered side by side on the same row. I tried every possible approach but it isn't getting rendered as...
testsys123
1

votes
1

answer
1.4k

Views

Pass HTML hidden field value in @HTML.BeginForm

I want to pass a hidden field value on click of submit button into my action method. This needs to happen on click of a button which posts a file. Below is the Razor code for HTML form with Post method that accepts the file. @using (Html.BeginForm('UploadProject', 'Admin', FormMethod.Post, new { enc...
Souvik Ghosh
1

votes
1

answer
165

Views

Razor Html.BeginForm Submit button works in every browser except chrome

I've been searching and found various answers but so far none seem to hit on my issue here. Seen things not working in other browsers but not yet chrome and I don't use chrome much. My issue is that when I click the submit button to this login form, it works in every single browser except chrome. Th...
Daniel Jackson
1

votes
0

answer
268

Views

Creating recursive method helper with Func<>

I have two method helper with theses signatures: @helper CreateNavigation(int parentId, int depthNavigation) @helper Navigation(int parentId, int depthNavigation) I have tried to convert it to a proper method for using in ASP.NET Core 2. But I got an error in VS2017 IDE that is: 1- Use of unassigne...
Jahan
1

votes
1

answer
202

Views

Reading line-by-line Hebrew text file shows gibberish no matter which encoding I use, why?

I made the site Text-Files-Oriented. The site is in Hebrew, using Razor Pages, Asp.Net Core 2.Environment: Visual Studio 2017 with all updates. In _Layout file I have: also, in site.css: body { background-color:black; padding-top: 50px; padding-bottom: 20px; direction:rtl; /*right to left*/ font-fam...
DJ5000
1

votes
1

answer
149

Views

ASP.Net MVC Razor Document Downloading as Corrupt

I'm working on an ASP.Net project that is based off of Razor. We are posting documents from the client side using formdata and need to change the name of this file based on who is uploading it. We have a method for doing so, which you can see here: var fileToSave = ''; if (filename != null) { file...
Quinton Chester
1

votes
1

answer
484

Views

Visual Studio 2017 adding unwanted dll's after publishing

I have a web application built using .NET Framework 4.5.1 When i publish it from VS2017, VS2017 adds unwanted dll's, not listed in the references, which are : System.Web.Mvc.dll System.Web.Razor.dll System.Web.Webpages.Deployment.dll System.Web.Webpages.Razor.dll When i try to publish from VS2013 it...
E. Hysenaj
1

votes
2

answer
378

Views

RazorEngine namespace not found in cshtml

I have a project with the razor engine package installed (https://github.com/Antaris/RazorEngine). I have multiple templates and I cannot compile some of them. The error is always the same: The type or namespace name 'X' does not exist in the namespace 'Y' My project does not use MVC. Only the Razor...
Ricardo Racciore
1

votes
0

answer
43

Views

Precompiled Views and CompilationCallback

I've defined a compilation callback for my MVC views like var mvc = services.AddMvc(); mvc.AddRazorOptions(razorSetup => { razorSetup.CompilationCallback = context => { // context.Compilation = context.Compilation.AddReferences(...) }; }); This works great - and while debugging, there's no problem -...
Wolfgang Kluge
1

votes
0

answer
221

Views

Collection with GUID id not binding

I have a pretty simple pair of classes: public class Question { [Key] public int QuestionId { get; set; } [Required] [Display(Name ='Question Text')] public string QuestionText { get; set; } public virtual IList Answers { get; set; } } public class Answer : IValidatableObject { [Key] [DatabaseGenera...
Matt Burland
1

votes
1

answer
377

Views

@Url.RouteUrl is empty in ASP.Net MVC 5

I have the following Action on a Controller in ASP.Net MVC 5: [Route('Sprache/{languageName}/Kurs/{courseName}/Text/{value}/Test/{referenzID}', Name = 'Textauswahl')] public ActionResult SelectedText(string languageName, string courseName, string value, string referenzID) { return View('Show...
Darem
1

votes
0

answer
66

Views

What are the drawbacks of implementing Web Api using inline handler methods of razor pages

As Razor pages can have inline handler methods and pages can be added to a running website without a full deployment. @page @{ public void OnGet() { } public void OnPost() { } } Thinking of a case when this dynamic addition to site features is a real plus point. What are some drawbacks (apart from...
eadam
1

votes
0

answer
652

Views

Running an ASP.NET Core Pipeline using Azure Functions

This was posted back in August https://social.msdn.microsoft.com/Forums/expression/en-US/c3e9f882-541f-48a2-a856-956ad3383f67/running-an-aspnet-core-pipeline-using-azure-functions He talks about using a catch-all function and then somehow running the HttpRequestMessage through Asp.Net Core How can I...
Paul Shell
1

votes
1

answer
54

Views

ASP.NET - load more than two

I want to load from my db all photos for that product which meets the condition > 2. When PCProductID has got one record in PCPhotoID i want to add single image but when it repeat itself e.g. PCProductID == 2 has got two records PCPhotoID, I want them to load in slider. I don't know how to write co...
1

votes
1

answer
53

Views

How can highlight a date in jQuery?

I cannot dynamically highlight the date in calendar, only static dates highlight if I do: eventDates[new Date('01/09/2018')] = new Date('01/09/2018') Here is my code: $(function() { // An array of dates var eventDates = []; $.ajax({ type: 'GET', url: '@Url.Action(' GetEvents ', ' Home ')', dataType:...
Arslan
1

votes
0

answer
30

Views

Ajax call throwing off anchor tags

I current have a page that displays from top to bottom: a responsive table containing a list of classes my company offers, a map showing the location of each class, and an agenda for the class. My employer would like me to add an anchor link in another page that links directly to the agenda portion...
DannyD
1

votes
0

answer
103

Views

How do I filter a foreach loop in Razor? Preferably with JavaScript though I'm pretty sure with how MVC works it won't be possible

Sorry in advance for the probably super simple question, and for my terrible programming vocabulary. Please let me know if I need to add any more info. I have an Umbraco project I'm working on but I'm a bit new to Razor and how everything interacts with each other. I've populated a table with a fore...
Andrew Massery
1

votes
0

answer
62

Views

ASPNET CustomValidation on List of Editor Templates, add input-validation-error css class on nested fields

How do I get my editor template field to apply .input-validation-error css class for custom validation on a collection field property? Normally I'd add a decorator directly on the view model property but in this case, the validation attribute is on the parent view model for the collection. I tried t...
ooXei1sh
1

votes
1

answer
743

Views

MVC BeginCollectionItem

I'm having some issue getting my partial view BeginCollectionItem to save to the database. I have a form which has a dynamic number of 'sections' that can be added to the page, and within each of these fields there is a text box where the user can enter the section name. As far as I can tell the Be...
Lucy Foster
1

votes
0

answer
85

Views

asp-page tag helper inserts encoded url inside form

I have a razor page with two page handlers: public IActionResult OnGetDisTest(int Id) { discussion = _service.GetDiscussion(Id, null); return Page(); } public IActionResult OnGetDisTestThread( int Id) { discussion = _service.GetDiscussion(null, Id); return Page(); } Accessing...
greedyLump
1

votes
0

answer
727

Views

How can I get precompiled razor files when deploying .NET Web Application?

I am tasked with improving IIS preloading and initializing of applications on our server. I have implemented application initialization and preload of application on IIS, but still there is a long wait time when recycling/restarting application pool. I have found some useful links which I thought wo...
John Dover
1

votes
2

answer
391

Views

Material design layout grid more than 12 colum

I'm trying to create a grid to which has one column per day of the month. So I need up to 32 columns in a single row (1st label + days of the month) I'm using a for in order to add divs dynamically. @{ Days: for (var i = 1; i
1

votes
0

answer
48

Views

Recaptcha widget not closing and doing multiple valid callbacks

I have a page using multiple recaptcha's like this: var recaptchaElements = []; @foreach (var item in Model) { ...
Harry
1

votes
1

answer
63

Views

Return dropdown string from second table

I have two tables I need to join for my Razor Page view. The first table called 'Account' contains an Account record with a int Status. The second table called 'AccountStatuses' contains possible statuses for the Account. Scaffolding created the following code in Account\Index.cshtml.cs public IL...
MikeK
1

votes
1

answer
50

Views

What is the best way to handle the view routing in Web API Razor

I have this doubt, because always when I create a Web API project I use the API controllers to get data and I create a normal controller where I define all my methods that returns ActionResult to redirect to the views and I am not sure if this is the best way. What is the correct way to do this?
user3442776
1

votes
0

answer
32

Views

Is there a method to standardise form content in MVC razor views?

I have a standardised form layout like this: @Html.AntiForgeryToken() @Html.HiddenFor(i => i.Id) Publishing @Html.EditorFor(x => x.PublishOptionsEditor) Content @Html.EditorFor(x => x.Title) @Html.EditorFor(x => x.Slug) @Html.EditorFor(x => x.OneLiner) @Html.EditorFor(x => x.HtmlContent) @Html.Edit...
Martin Hansen Lennox

View additional questions