razor

Text box default value in Razor syntax

依然范特西╮ 提交于 2019-12-25 02:35:07
问题 <div class="editor-label"> @Html.LabelFor(model => model.UserName) </div> <div class="editor-field"> @Html.EditorFor(model => model.AccountModel.UserName) @Html.ValidationMessageFor(model => model.AccountModel.UserName) </div> On this page load (View load), I would like the Username text box to have its value automatically populated from the standard aspnet membership informtion. How can assign this default value to the text box. Please help. thank you 回答1: In your controller action you could

How to set Razor Layout file just specifying the name?

落爺英雄遲暮 提交于 2019-12-25 02:29:01
问题 First a little context. When you call Html.RenderPartial you send the View name, that view will be searched at locations specified by RazorViewEngine.PartialViewLocationFormats: Html.RenderPartial("Post", item); When you set the Layout property at Razor page, you can´t just say the name, you need to specify the path. How can I just specify the name? //Layout = "_Layout.cshtml"; Layout = "_Layout"; //Dont work I need this because I overrided the RazorViewEngine.MasterLocationFormats. Currently

Razor: Auto-complete text box inside jqGrid, How to bind values?

ε祈祈猫儿з 提交于 2019-12-25 02:26:46
问题 I'm developing a page where i need to show a jqGrid with inline editing mode. (Razor view, MVC3) The Grid will have no rows initially but an empty row to add items and hitting "enter" upon the last field should save the row data, and then empty 2nd row should get created. There are 4 columns in the Grid and the first column should be auto-complete. I have already written multiselect jqGrid which works fine. But now the approach changed to auto-complete. I have already written controller

CascadingDropDowns Webmatrix

╄→гoц情女王★ 提交于 2019-12-25 02:25:48
问题 So i was following this tutorial http://www.mikesdotnetting.com/Article/196/WebMatrix-jQuery-Cascading-Dropdown-Lists Everything works nice, but when i save to the database the first dropdown, pass me the ID and i can't figure it out how to pass the name instead of the ID. <select id="categoryId" name="categoryId"> <option value="">-- Select Category --</option> @foreach(var category in categories){ <option value="@category.CategoryId">@category.CategoryName</option> } </select> I know that

Problem with ajax.actionlink helper, return string

蓝咒 提交于 2019-12-25 02:25:21
问题 I'm using MVC3 with Razor. I have the following helper: public static class ImageActionLinkHelper { public static string ImageActionLink(this AjaxHelper helper, string imageUrl, string actionName, object routeValues, AjaxOptions ajaxOptions) { var builder = new TagBuilder("img"); builder.MergeAttribute("src", imageUrl); builder.MergeAttribute("alt", ""); var link = helper.ActionLink(builder.ToString(TagRenderMode.SelfClosing), actionName, routeValues, ajaxOptions); return link.ToHtmlString();

Place ajax $get() into a javascript variable

故事扮演 提交于 2019-12-25 02:25:14
问题 I need to place the result of an ajax get into a javascript variable. The following works $.get('@Url.Action("_Edit", "News", null)/' + guid_News, function (html) { $("#divEdit").html(html); }); This does not work var editHtml = ""; $.get('@Url.Action("_Edit", "News", null)/' + guid_News, function (html) { editHtml= html; }); $("#divEdit").html(editHtml); Have also tried var editHtml = ""; editHtml = $.get('@Url.Action("_Edit", "News", null)/' + guid_News, function (html) { return html; }); $

@html razor radio buttons mvc5

荒凉一梦 提交于 2019-12-25 02:12:19
问题 here's my viewmodel public class UserResponseModel { public string QuestionId { get; set;} public string QuestionText { get; set; } public bool IsChecked { get; set; } } so, for checkboxes this works beautifully for (var i = 0; i < Model.UserResponses.Count; i++) { <div class="row"> <div class="col-md-4"> <div class="form-group"> @Html.HiddenFor(x => x.UserResponses[i].QuestionId) @Html.CheckBoxFor(x => x.UserResponses[i].IsChecked) but for radio buttons this does not for (var i = 0; i <

DropDownList Property to display

我的梦境 提交于 2019-12-25 02:08:13
问题 I have the following classes: User and Medic , that inherits from User . User has: Id , Name ... Medic has: Crm (numeric value)... In a view, I want do display a DropdownList with Medic's Id for options value, and Name (inherited) for display... But using @Html.DropDownList("MedicId") I have, for default, the Crm property being displayed. Someone knows a way to set the display property to Name ? 回答1: Sorry, I have not observed, but in my Controller I have the way to do it ViewBag.MedicId =

Formatting nullable decimal in RazorEngine

梦想与她 提交于 2019-12-25 02:04:01
问题 RazorEngine.dll version is 3.2. Example code inside a razor engine template (cshtml file) : @foreach(var row in Model.Trades) { <tr> <td> @string.Format("{0:N2}",row.Amount) </td> </tr> } where row.Amount is defined in the Trades class as : public decimal? Amount; The stack trace fromRazorEngine is : > System.ArgumentNullException was caught HResult=-2147467261 > Message=Value cannot be null. Parameter name: args Source=mscorlib > ParamName=args StackTrace: > at System.String.Format(String

How to create users and store them in a database and link them to windows authentication logins

久未见 提交于 2019-12-25 01:53:12
问题 What I want: An intranet application where only people who are logged in can see the application... and an Admin and Member role. 1: I have created an MVC 5.0 web application (for intranet). It has a Home view with a home controller... I have an Admin view with an admin controller. The home page has a link (well it's not a link yet but whatever) on it that is conditional: @if(User.IsInRole("Admin")){ <li>Admin</li> @*Will be link to admin controller action*@ } I would like to create 1 user