Questions tagged [razor]

11434 questions
0

votes
0

answer
16

Views

Trying to use a non-static object in a List of objects

I am working with Razor Components and have a question about using non-static values in a list of objects. I have the following code: @page '/CircularGauge/DefaultFunctionalities' @using Syncfusion.EJ2.RazorComponents.CircularGauge @functions { int myInteger = 21; public List axes { get; set; } = ne...
arlan schouwstra
0

votes
0

answer
4

Views

IIS: cshtml pages in an application under a site

On a Windows Server 2016, I have a website with cshtml pages. Under this site, I need to add another site with cshtml pages through 'Add Application' in IIS Manager (version 1607). Let me call this added application 'app' Here is the problem. This link http://example.com/app/index.cshtml produces...
curious1
1

votes
1

answer
1.8k

Views

Generate Razor HTML emails in dotnet core 2

How can you generate emails (html) using Razor in dotnetcore - and not from an MVC app (think from a console app)? RazorEngine does a great job in .net 4.x, but is not working in dotnet core. RazorEngineLight works in dotnet core 1.x, but not in 2.x. Some other options are mentioned in this post: Us...
Kjensen
1

votes
2

answer
654

Views

ASP.NET Core ViewData, BindProperty or TempData?

In ASP.NET Core Views and Razor Pages we can use: public class LoginModel { [BindProperty] public bool DisplayCaptcha { get; set; } // OR [ViewData] public bool DisplayCaptcha { get; set; } // OR [TempData] public bool DisplayCaptcha { get; set; } } To share data between View/Page/Controller... But...
Vanderlei Pires
1

votes
2

answer
37

Views

Need to split a string and count occurrence

I have a string in my ViewData. I need to split it be COMMA and count the occurrence of words. i.e. ViewData['words'] = 'apple,orange,grape'. I need to split and get the answer as 3.
Ranjith Kumar K
1

votes
1

answer
17

Views

Why PartialAsync doesn't call coresponding controller method?

I have a .NET Core 2.1 MVC application. I have a Home controller that looks like this: public class HomeController : Controller { public IActionResult Index() { return View(); } public IActionResult CountView(MyModel model) { ... return PartialView(model); } } In the Index view I want to display a p...
Szybki
0

votes
1

answer
6

Views

ASP.NET Core Razor: Conditional attribute without value

I want to conditionally render a readonly attribute in an . In the ASP.NET Core dialect of Razor the interpretation of attributes is a little different opposed to System.Web.Mvc. In System.Web.Mvc I used to do: In ASP.NET Core, the same does not work: no error, but the attribute isn't rendered eithe...
Sebazzz
0

votes
2

answer
25

Views

Need to pass text box values as parameters when calling controller method on button click

I'm working on an MVC form that's supposed to let the user enter some descriptions of their problem in various fields, and the text in those fields will then be compiled into an email and sent to us after the user clicks the 'Submit' button. I've got enough wired up to pass hardcoded strings as par...
R. D.
1

votes
2

answer
1.2k

Views

Can't open any .cshtml file in Visual Studio 2017

I have Visual Studio 2017 Community edition. These are the only steps I have taken to reach this error. I create a new .NET Core 2.0/2.1 Web Application (both versions result in error)\ I choose Web Application (Model-View-Controller) After I create the project, I try to open any of the .cshtml file...
riley lyman
1

votes
1

answer
648

Views

asp.net core select validation with data annotation not working

I have spent a remarkable amount of time to find out but I couldn't. When I post my model without selecting any option - in fact selecting 0 - Select - option, the Required validation is not working. I also tried removing the programatically added default option from service code to the view code,...
ibubi
1

votes
2

answer
336

Views

asp-for in checkbox throws and error in asp.net core

Here i have used two checkbox Send Report Send Invoice and data type for both checboc i.e asp-for='SendReport' and asp-for='SendInvoice' is bit. Now the problem is that when ever i try to load the page its throws error as below Unexpected 'asp-for' expression result type 'System.Nullable`1[[System.B...
redcaper71
1

votes
2

answer
88

Views

Clickable button inside of a table

I am writing a View of a composite list of employee information. The view will display information such as first name, last name, job code etc... My one problem is that I would like to have the boolean cells be clickable buttons. For example: The HasHealthcare column will contain boolean values....
HelpMyHospital
1

votes
1

answer
63

Views

Date is not set in DateTime Picker in Asp.net MVC

I have one edit form, On-grid click, all value assign to relative fields, I have one field that is DOB, and I try to assign DOB in datepicker, but DOB do not assign in datepicker & where I am going to wrong that I am not able to understand I am working with Asp.net MVC using c# Scripts Code @Html.L...
shivani
1

votes
1

answer
57

Views

Why is the Razor UI class library built as .NET Standard and not in .Net core

I've created a razor class library in a .Net core application. the library built as .NET Standard and the main web project and the others class libraries built as .Net core 2.2, When I'm trying to add a reference to my razor class library, I get this error: project is not compatible with net standar...
Alaaeddine HFIDHI
1

votes
2

answer
6.4k

Views

Additional parameters for TextBoxFor() in ASP.net MVC3

I was using a textbox to do the following: This basically shows a textbox which is disabled under specific circumstances. I decided to replace this with a more 'mvc-friendly' way. @Html.TextBoxFor(m => model.value1, new { id = 'blah' }) But not sure how to add in the disabled attribute (Dynamically)...
JustAnotherDeveloper
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

View additional questions