razor

MVC Html.ActionLink not rendering. Can you spot what I'm doing wrong?

柔情痞子 提交于 2019-12-23 23:46:45
问题 I have an Html.ActionLink inside an IF statement in a partial view that is not rendering a hyperlink for me as expected. I placed a breakpoint on the line and confirmed that the IF statement is in fact being satisfied and the code inside of it is running. I also, just as an extra measure, tried substituting the Substring with a hard string. Any ideas why no link is rendering for me with this code? <p> Resume (Word or PDF only): @if (Model.savedresume.Length > 0) { Html.ActionLink(Model

How to display a TimeSpan in MVC Razor

混江龙づ霸主 提交于 2019-12-23 23:04:50
问题 So I have a duration in seconds of a video and I would like to display that duration in Razor. Currently I am using @TimeSpan.FromSeconds(item.Duration).ToString() However the rest of the code I am using uses @Html.DisplayFor(modelItem => item.Description) Is there way to get the duration (currently an int) to display a as a timespan? using the @Html.DisplayFor syntax. The item.duration is pulling form a Entity Framework model which is held as a int in the database. 回答1: You can extend your

Use StaticPagedList with PagedListRenderOptions

你说的曾经没有我的故事 提交于 2019-12-23 22:59:51
问题 Using PagedList of MVC. Not able to get Property: PagedListRenderOptions { DisplayLinkToFirstPage = PagedListDisplayMode.IfNeeded } Note that I'm using StaticPagedList not PagedListPager . My Requirement is : pagedlist-pagination Not able to find syntax to use StaticPagedList with PagedListRenderOptions 回答1: Pass the paging meta data as separate property and construct the IPagedList in the view. Like this: public class PagedClientViewModel { public int? Page { get; set; } public List

How to control access to forms fields on a ASP.Net MVC 3 view?

假如想象 提交于 2019-12-23 22:34:35
问题 Example User "jtirado" is assigned role "HR-Assistant", can access route "mymvcapp/employeee/edit/1452" to edit employee (id:1452) data. Being "HR-Assistant", this user can change employee telephone number and e-mail, can view employee salary but not edit the amount. Telephone number, email, salary are dabatase fields and are represented/rendered by a "asp.net-mvc-control" or "HTML-control" on the View. So I want to restrict access to these controls based on user's role. Previous experience I

ASP.Net MVC Ajax.BeginForm OnComplete pass c# arguments in Razor view

混江龙づ霸主 提交于 2019-12-23 22:17:23
问题 I have the following code in a MVC c# Razor view: @{string url = "/Projects/_MonthRangesScriptsPartial";} @using (Ajax.BeginForm( "_MonthRanges", "Projects", new { id = ViewBag.InputResourceID }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "MonthRanges", InsertionMode = InsertionMode.Replace, OnComplete = "updategraphArrayScript(@url,@ViewBag.InputResourceID)" })) The code works almost perfectly, but I would like to resolve the c# variables to their values in the OnComplete line.

Handle multiple submit buttons with “Remote” validation in MVC4 razor

♀尐吖头ヾ 提交于 2019-12-23 20:48:14
问题 I have two buttons in my Event form as below, @using (Ajax.BeginForm("Create", "Events", new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = "POST", OnSuccess = "updateSuccess" }, new { @id = "updateEventForm" })) { <div class="modal-body form-horizontal"> <div class="form-group"> <label class="col-sm-2 control-label">@Html.LabelFor(model => model.Code)</label> <div class="col-sm-10"> @if (Model.EventID <= 0) { @Html.TextBoxFor(model => model.Code, new { id = "txtCode",

Foreach ViewBag data gives 'object' does not contain a definition for 'var'

╄→尐↘猪︶ㄣ 提交于 2019-12-23 19:42:49
问题 I have a controller that is building a query from Linq to Sql to pass into the ViewBag.products object. The problem is, I cannot loop using a foreach on it as I expected I could. Here's the code in the controller building the query, with the .ToList() function applied. var products = from bundles in db.Bundle join bProducts in db.BundleProducts on bundles.bundleId equals bProducts.bundleID join product in db.Products on bProducts.productID equals product.productID join images in db.Images on

Getting a list of radio button values in ASP MVC 3

扶醉桌前 提交于 2019-12-23 19:18:47
问题 I am developing a page for rating questions. In the view, I have a list of questions and 5 radio buttons in front of each one of them. <input name="evalId" type="hidden" value="@Model.Evaluation.EvalId" /> foreach (var question in questionList) { <input name="questionId" type="hidden" value="@question.QuestionId" /> <div class="row_star" style="border-bottom : 0 none; background: none;"> @if (!String.IsNullOrEmpty(question.QuestionTitre)) { <p>@question.QuestionTitre.TrimEnd()</p> } @* here

Display expression value in Razor

泪湿孤枕 提交于 2019-12-23 18:29:56
问题 I want to display the value of the below expression as a text in razor view. @(doc.Extension ?? string.Empty).ToUpperInvariant(); I've tried every variant but nothing seems to work. I know i can use a temp variable to store the value of this expression but I was wondering if there was a way to do this inline. @((doc.Extension ?? string.Empty).ToUpperInvariant();) @{@:@(doc.Extension ?? string.Empty).ToUpperInvariant();} 回答1: If you don't use a semicolon, Razor will interpret your code as an

ASP.NET _ViewStart.cshtml - Getting the Request

寵の児 提交于 2019-12-23 18:01:42
问题 I have an ASP.NET app. My app has a _ViewStart.cshtml file. That file looks like this: @using MyCompany.MyApp; @{ Layout = "/Views/Shared/_Layout.cshtml"; var p = HttpContext.Current.Request.QueryString["parameter"]; ViewBag.QSParameter = p; } When I execute this code, I get the following error: The name 'HttpContext' does not exist in the current context I don't understand. Isn't _ViewStart.cshtml kind of the "shell" for the views? I'm trying to figure out how to globally read a query string