razor

Using Url.Action in javascript

独自空忆成欢 提交于 2020-01-11 04:23:04
问题 I am trying to use the Url.Action method to correctly generate the required Url for an ajax call but I'm running into problems when trying to build the RouteValues, here's the problem line of code: var url = @Url.Action("ViewFile", "Default", new { itemId = $(this).data("itemid") }); As you can see, I'm trying to assign the result of the JQuery $(this).data("itemid") to itemId in the RouteValues. Is there a way using razor syntax which will allow this code to compile? 回答1: You are confusing

Calling Action in Razor Pages

一笑奈何 提交于 2020-01-11 03:16:06
问题 as a newbie to Razor Pages I have a question regarding calling methods from Razor Page. I have a method called subtractProduct defined in my domain model. In my Index Page code I define IActionResult sellProduct which calls subtractProduct on specified ProductId. But I have no clue how to call this method on my html page. I've tried a lot of combinations, but nothing seems to be working. Anyone knows how to deal with this? Any help is greatly appreciated! My domain model is: public class

asp.net mvc 3 razor. navigate to view on table tr click

瘦欲@ 提交于 2020-01-10 20:24:06
问题 I have users list table how i can navigate on url: "../users/showprofile?userid=" I want to make table when user clicks on table row navigate on current user profile Thanks 回答1: Without using jQuery, assuming you're in a foreach loop like something below, just change the tr definition to be something like: @foreach (var user in Model.Users) { <tr onclick="location.href = '@(Url.Action("ShowProfile", "Users", new { userId = user.UserId }))'"> //rest of your markup for that table row </tr> } 来源

Razor Layout doesn't work if file is called _ViewStart.cshtml

旧街凉风 提交于 2020-01-10 19:09:08
问题 I have an MVC3 web app to which I want to start using whole Razor views. Most of the site is working fine with a Site.Master so I've packaged up most of it into partial views and am trying to add a layout with the same content. After reading Scott Gu's blog I've added a file called _ViewStart.cshtml in my ~/Views directory so that it'll be applied by default. Unfortunately this gives me the error: The name 'RenderBody' does not exist in the current context If the file is called _viewstart

Can't get site root url in asp mvc

天大地大妈咪最大 提交于 2020-01-10 11:57:46
问题 I need to get site root url in razor page in javascript code: ... var siteRootUrl = '@Url.Content("~")'; ... But all I get from this is '/'. 回答1: To get the current host with port (mysite.com, www.mysite.com or localhost:9876) Request.Url.Authority To get your current application folder: (/ or /appfolder/) Url.Content("~/") To mix them? String.Format("{0}://{1}{2}",Request.Url.Scheme, Request.Url.Authority,Url.Content("~/")) OR (As torm pointed out) Url.Action("", null, null, Request.Url

How do I update a model value in JavaScript in a Razor view?

余生颓废 提交于 2020-01-10 08:09:06
问题 I want to update model value in JavaScript as below but it is not working. function updatePostID(val) { @Model.addcomment.PostID = val; } in Razor view as shown below foreach(var post in Model.Post) { <br/> <b>Posted by :</b> @post.Username <br/> <span>@post.Content</span> <br/> if(Model.loginuser == Model.username) { @Html.TextAreaFor(model => model.addcomment.Content) <button type="submit" onclick="updatePostID('@post.PostID');">Add Comment </button> } } Can anyone tell me how to assign

Redirecting from cshtml page

浪子不回头ぞ 提交于 2020-01-10 03:27:10
问题 I want to redirect to a different view depending on the result of a dataset, but I keep getting returned to the page I am currently on, and can't work out why. I drop into the if statement the action gets called but once i return the view to the new page, it returns me back to the current page. CSHTML page @{ ViewBag.Title = "Search Results"; EnumerableRowCollection<DataRow> custs = ViewBag.Customers; bool anyRows = custs.Any(); if(anyRows == false) { Html.Action("NoResults","Home"); } //

Asp.net razor textbox array for list items

隐身守侯 提交于 2020-01-09 11:09:17
问题 I can't find or figure out how to take a list of items (cupcakes) and display them in razor with a quantity field. What is happening is I am not able to get the values for each cupcake quantity in the list. Can you do textbox arrays in Razor? VIEW <div class="form-group"> <label>Cupcakes</label> @foreach (var cupcake in Model.CupcakeList) { @Html.TextBox("CupcakeQuantities", cupcake.Id) @cupcake.Name <br/> } </div> MODEL public List<Cupcake> CupcakeList { get; set; } public List<int>

Asp.net razor textbox array for list items

时光总嘲笑我的痴心妄想 提交于 2020-01-09 11:04:05
问题 I can't find or figure out how to take a list of items (cupcakes) and display them in razor with a quantity field. What is happening is I am not able to get the values for each cupcake quantity in the list. Can you do textbox arrays in Razor? VIEW <div class="form-group"> <label>Cupcakes</label> @foreach (var cupcake in Model.CupcakeList) { @Html.TextBox("CupcakeQuantities", cupcake.Id) @cupcake.Name <br/> } </div> MODEL public List<Cupcake> CupcakeList { get; set; } public List<int>

ASP.NET Actionlink with glyphicon and text with different font

白昼怎懂夜的黑 提交于 2020-01-09 06:06:07
问题 I want to present a button with @Html.ActionLink but i need to have my application font in the text. With this code: <span> @Html.ActionLink(" Create New", "Create", null, new { @class = "btn btn-warning glyphicon glyphicon-plus-sign" }) </span> I get my button but the Create New text appears with the glyphicon font-family. Putting the glyphicon classes in the span doesn't change anything 回答1: You should not add the glyphicon class to the a-tag. From the Bootstrap website: Don't mix with