Questions tagged [razor]

Razor is a template language used by ASP.NET Web Pages and ASP.NET MVC (since version 3). It adds a layer of abstraction above HTML generation. It supports seamless transitions between HTML markup and C# or VB code. Transitions between markup and code are indicated by the "@" sign.

Filter by
Sorted by
Tagged with
0
votes
0answers
4 views

How to stretch HTML.TextBoxFor with class form-control

I'm trying to create a form with Razor, but the helper Html.TextBoxFor don't use all the width from the column. I'm using Visual Studio Community 2019 and Bootstrap. This is my code. <section ...
1
vote
1answer
15 views

ASP.NET Razor - Binding multiple properties and forms in one PageModel

I'm very new to working in Microsoft Visual Studio and I set up a new Razor Web Application following the documentation and now I want to combine some of the actions that are broken apart on several ...
1
vote
1answer
14 views

how to make ActionLink with 2 statements razor

i want to make a ActionLink in my index page when 2 Statements are not in my "GraduationStatus" column. When the "GraduationStatus" is "Graduated" and "Pass" i want to have a link that redirect to the ...
1
vote
0answers
13 views

.modal(dispose) is not a function boostrap 4.3

Running into the Uncaught TypeError: $(...).modal is not a function error when i try and use $('#editAppModal').modal('dispose'); I don't think this is a script reference issue, because I don't ...
1
vote
1answer
26 views

How to access a json object in javascript files from a model passed to the view

I have a JSON object in my database that contains html inside it. I pass the object as part of a model to my view. I need to access the object and read it in the javascript files for the page. However ...
1
vote
2answers
37 views

Http Put is no being sent from a razor page [duplicate]

I tried to create a simple HTML form like this using ASP.NET Core tag helpers: <form asp-action="RemoveScheduledTenancyDeletion" method="put" asp-route-tenancyId="@Model.Tenancy.TenancyId"> ...
0
votes
0answers
14 views

How to integrate Razor Pages in Razor Components

I have a razor components project (ASP.NET Core 3.0 Preview Template) where one application needs to have some javascript components (leaflet). So I decided to create a Razor Page (.cshtml) which ...
0
votes
1answer
17 views

Call void method by CSHTML page with input parameter

I'm building a simple MVC application. In my CSHTML file I'm build this code: <script type="text/javascript"> //modify as needed to make it pass in what you need. function ...
0
votes
0answers
7 views

Rendering view starts slowly

I have one action which returns a view. I also have two different user accounts. One user has been connected to many objects which are stored in session and the second one is connected to just one ...
0
votes
1answer
26 views

MVC Call method of controller by CSHTML page

I have a simple Web Application in C#. In Index.cshtml file, I want to insert a button, and when I click on it, call a method of my Controller. So I'm build this code: <div class="row" style="...
0
votes
1answer
49 views

removing value after decimal

I am converting a string to decimal using Convert.ToDecimal(). I am using this in razor engine. What I want is that it should come as rounded off to nearest integer value. I have tried Math.round, ...
0
votes
1answer
27 views

@Url.Action is null or “” in javascript when page loads

I have this function located in a controller called AccountCodes. [ValidateAntiForgeryToken] [HttpPost] public async Task<ActionResult> Process() { JsonResult result = ...
0
votes
1answer
26 views

Is there a quick way to get unique properties in an IEnumerable collection? [duplicate]

So I have this collection of items in my razor page view I display these items in a table like so: @foreach (var item in Model.Items) { <tr class="itemsRow"> ...
0
votes
0answers
22 views

How do I get a list of objects from a form in razor?

I need to receive a list of items from the user. Specifically I have recipes(a restaurant menu item) that has a list of ingredients. I need a page where the user can put in any number of ingredients ...
0
votes
0answers
13 views

Why does the environment tag helper work on my machine but not on Azure?

This is a section on our _Layout.cshtml that I'm about to throw out the window. <!-- CSS Scripts --> <environment include="Development"> <script src="/ts/CS.js" asp-append-...
0
votes
1answer
28 views

How to set a default value from the model in a DropDownListFor?

I'm using DropDownListFor to create a drop-down of enums. I am creating an edit profile page that lets the user edit there level, so I want by default to have what they had in their profile selected, ...
0
votes
1answer
29 views

How to pass parameter to controller function

So I have a form like this: @using (Html.BeginUmbracoForm<DataController>("SetYear", null, new { @id = "yearDropdown" })) { <div class="form-group"> <select id="Year" name="...
0
votes
0answers
20 views

How can i use a list of properties with razor to complete the crud

I'm working on a project with .NET framework and asp.net, it's a web application that can handle certain forms for an insurance company. The concept is to fill the forms in order to complete the ...
-4
votes
1answer
23 views

How to redirect button to another asp.net webpage using c#? [on hold]

I am trying to redirect the page to checkout page once user click the checkout button. As i already have a form =post method. so i cant lump it together with the post method. is it possible to do ...
0
votes
2answers
34 views

EF entities not being committed to database when adding and saving are separate methods

I am trying to create an expense report application using Razor and EF. I have two entities: 1. ExpenseReport and 2. LineItem. There is a 1:N relationship using FK b/t ExpenseReport and LineItem. I ...
1
vote
1answer
12 views

ViewComponent not found in Asp.NET Core 2.2 using Razor Pages

I have created a very simple view component (/ViewComponents/MenuViewComponent.cs): namespace MySite.ViewComponents { public class MenuViewComponent : ViewComponent { public Task&...
-2
votes
0answers
15 views

Convert razor to html

convert the confirm password field in html and password field in razor since it is in the model of mvc <div class="form-group"> @Html.LabelFor(m => m.Password, new { @...
0
votes
1answer
13 views

href is truncating querystring

I have following querystring in a variable var redirectTo = "http://localhost/DGS.DGSAPI.UI/ORDERONLINE?addr=10 n main&apt=&zip=44408&customer=N"; rendered on View like: <a [email protected]
1
vote
2answers
51 views

How to pass data from a model (MVC) to @url.Action() to plot a chart

I want to plot a pie chart. The chart data is in a model/controller. And I have a @Url.Action() to display the pie chart. How to pass the chart data from model to @Url.Action() here - eventually ...
0
votes
1answer
29 views

How do I redirect to another page in my application using mvc

I am using Web API MVC SPA application and I would like to know how to redirect to another page using javascript. I have pasted my code below but it is not working This is the code I have at the ...
0
votes
1answer
28 views

Difference between passing and not passing a view name in the View() method when we return from an Actionresult

What is the difference between passing and not passing a view name to the View() method in an Action? public ActionResult Index() { return View(); } VS public ...
-2
votes
0answers
43 views

Switch statement not executing in Razor view

I'm trying to execute a switch statement in a view. I'm new to ASP.NET. The class for a certain div is dependent on the Model. I assign the "style" variable a string that is a class that will be on ...
0
votes
1answer
19 views

Dynamic and Nested Form Container

I am quite new to front-end programming so I am probably lacking the correct terminology but I am simply looking to create a dynamic/nested form. As shown in the image, I am trying to find a way to ...
0
votes
1answer
31 views

Generate list based on selected option

I'm trying to create a page for admins to create new users. When these users are created they will also have a role that they are assigned, and each of those roles will have a list of associated ...
0
votes
1answer
56 views

Load ASP.NET MVC views and controllers code from database

I have a system in which the end-user is a developer who can create ASP.NET MVC views/controllers and run them on the fly. Currently, I have two database tables, one to store the view name and code ...
0
votes
0answers
15 views

Ajax Context Value provider returning null

I'm currently using MultipleButtons and it works great. I'm trying to get multiple buttons to call the same form that later will call seperate functions in the controller. When I'm using Html....
0
votes
1answer
36 views

Some Razor Views are not Being Compiled on Publish in Visual Studio 2019

I have a bit of a complicated solution where I have two ASP.NET Core 2.2 projects and another project that they both share. The shared project contains four Razor views that I XCOPY into the other ...
0
votes
2answers
42 views

ASP.NET core 2.2 Unhandled exception when creating a form

I am currently creating a web application that takes in a new user, adds their information to a list, and then displays the users. When I follow the link to my form with validation (a form I have used ...
0
votes
3answers
25 views

Force user to click button at least once before posting

I want the user to click a button to add a row on my page before they post the form info. Basically there is a button on the page which adds a string line to a div, and i want to make sure they've ...
-1
votes
0answers
41 views

How to close the current browser tab in cshtml?

I have a cshtml form file. I am trying to close the browser tab containing this file. However, I am not trying to close the tab right after the submit button is clicked, there are also some c# codes ...
0
votes
1answer
39 views

Razor - How to determine RenderFragment Element name?

I was creating simple razor component from existing html template. i want to make different conditions based on type of child given (from parameter) i have existing MenuItem and AnotherMenuItem ...
0
votes
1answer
38 views

How to open a html file on current browser tab using Process.Start()

I have the code below System.Diagnostics.Process.Start("ClosePopup.html"); ClosePopup.html is the html file below <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &...
0
votes
1answer
41 views

How should I handle rendering components with slight variations between them?

I've been looking at the new Blazor framework from Microsoft. As part of this, I've been creating a little StackOverflow clone to experiment with some of the concepts. I'm trying to find a way to ...
0
votes
0answers
15 views

Implementing validation on a hidden input

I am trying to validate a hidden input via Razor validation. I have the control <div name="serverTB" id="serverTB"> <input id="ServerCheck" asp-for="serverCheck" type="text" hidden> ...
0
votes
0answers
18 views

Razor filter dropdown not filtering when selecting a projects

Hello I have a page that has two filters that are quite the same but one of them is not working right and I am not sure what is wrong with my code! image of the filter Thank you in advance! Here ...
0
votes
6answers
61 views

How to disable two submit buttons when one of them is clicked

I have two submit buttons in a cshtml file. <button type="submit" name="SubmitButton" value="accept" id="buttonAccept">Accept</button> <button type="submit" name="SubmitButton" value="...
0
votes
0answers
25 views

How string variable in razor becomes the html element in java script

I've declared a simple string variable in razor page to store a dynamic id of a div. @{ int i = 0; string divId = "Ratting_"[email protected]; } and used it like <div id="@divId"> Test Div ...
0
votes
1answer
20 views

How to convert a specific column value for all items in an IEnumerable?

I have an IEnumerable that I want to run HttpUtility.HtmlDecode() through a specific column for all items. This is an ASP.NET project as C# is saving my "<" and ">" into &lt; &gt; ...
0
votes
1answer
39 views

How do I get property of an Ienumerable in the view?

I'm trying to grab the last four ImageUrl properties in my razor page for each item in each category. I have a collection of categories that looks like this: public class CategoryIndexModel { ...
1
vote
1answer
28 views

How do I consume a JSon object that has no headers?

My C# MVC5 Razor page returns a Newtonsoft json link object to my controller (the "1" before \nEdit |" indicates that the checkbox is checked: "{\"0\": [\"6146\",\"Kimball\",\"Jimmy\",\"General Funny ...
0
votes
0answers
10 views

C# mvc5 calling second helper method defined by user does not get into set breakpoint

I have a partial menu in MVC5 for creating dynamic menus in page. But calling second helper method (createChildren) does not get into it just first { when I create a breakpoint there, and after that ...
0
votes
2answers
37 views

How to prevent page back and refresh by dispose model data in view [on hold]

I have a page which redirect from previous page by submiting a POST form, now whenever the user refresh or back and forth the page, the posted data still remain in the model. I want the data to be ...
0
votes
0answers
35 views

MVC: format value in form data at submission

I am sending a value from the form data which has to be received as decimal? with comma (,) punctuation. Since I am using input type="number" step="0.1" the punctuation on the client side is with a ...
0
votes
0answers
18 views

Update SQL Server database table entry via form submission in C# Razor [closed]

I have a form in CSHTML in Visual Studio in which a user submits updates to answers of a survey. The C# Razor code I've written connects to the related SQL Server database and is supposed to update ...
0
votes
0answers
14 views

Primitive Tag Helpers No Longer Purple in Visual Studio 2019

I understand completely how _viewimports works and I have that set properly. In previous versions of Visual Studio, if you targeted a primitive tag helper (like p or body), it would turn purple. In ...