Posts

Showing posts with the label razor

Convert C# string to JavaScript String

Image
Clash Royale CLAN TAG #URR8PPP Convert C# string to JavaScript String Does anybody know a way to convert a C# string to a JavaScript String in Asp.net. My code looks like this: <script> @{string thing = "Cats";} var thing = String(@thing); </script> </div> <body onload="eventAlert(thing)"></body> I think what you're looking for is a way to get a string value from server side (code behind) to client side (javascript). Is that right? – paqogomez Dec 19 '14 at 22:36 The eventAlert(thing) function simply shows the string as an alert, but the code above does nothing unless i manually pass in the string. – Sepehr Sobhani Dec 19 '14 at 22:38 ...

The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor'

Image
Clash Royale CLAN TAG #URR8PPP The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' Trying to teach myself some new tools, but I've managed to break my project. The solution is about a day old and consists of two projects. One is the application (created using the Visual Studio .NET Core 2.1 SDK + React Template ), and the other is the data layer (which is just a Models folder). Models The data layer was implemented today, and that's when things got rocky. I don't want to point the finger there immediately, because it could've happened with some other changes I was making at the same time. One or more compilation references are missing. Ensure that your project is referencing 'Microsoft.NET.Sdk.Web' and the 'PreserveCompilationContext' property is not set to false. The type or namespace name 'Hosting' does not exist in the namespace 'Microsoft.AspNetCore.Razor' (are you missi...

@Html.ValidationMessageFor() required field displaying message when populated

Image
Clash Royale CLAN TAG #URR8PPP @Html.ValidationMessageFor() required field displaying message when populated I am currently using ASP.net MVC (VB). I have a model with the following property: <Required(ErrorMessage:="Contact name is required")> Public Property contact_name() As String <Required(ErrorMessage:="Contact name is required")> Public Property contact_name() As String In my controller method (accepts a post request and binds various parameters to the model) I set contact_name from two other parameters : model.contact_name = first_name + " " + last_name model.contact_name = first_name + " " + last_name I return to my view containing a form which has an input field with a value of model.contact_name and I use the tag model.contact_name @Html.ValidationMessageFor(Function(model) model.contact_name @Html.ValidationMessageFor(Function(model) model.contact_name The problem is that the error message is always displayed, unles...

Inserting razor syntax inside javascript function

Image
Clash Royale CLAN TAG #URR8PPP Inserting razor syntax inside javascript function Im trying to loop over a collection of data inside a div like this but received and error that says Unterminated string literal. Strings that start with a quotation mark (") must be terminated before the end of the line. How can i solve this? <a href="@(eventItem.Url)" class="media-box__cover"> @if (listingImageUrl == "") { if (currentCount % 2 == 0) { <div class="media-box__cover-image" style="background-color: #ffd205;"></div> }else { <div class="media-box__cover-image" style="background-color: #0d9430;"></div> } } else { <div class="media-box__cover-image" style="background-image: url('@(listingImageUrl)');"></div> } </a> into this, for (i = 0; i < json["data"].length ; i++) { if(t...