asp.net-mvc-5

MVC 5 Razor view not rendering HTML within if condition

烂漫一生 提交于 2019-12-14 01:24:08
问题 This is the MVC 5 razor view code: ForestView.cshtml @model Forest.Tree @{ var resultHtml = string.Empty; } <div id="divTreeSearch> @(Html.Kendo().PanelBar(). Name("panelbar") .Items(panelbar => {panelbar.Add() .Content(@<text>@Html.Partial("_TreeSearch", Model, ViewData)</text>);})) </div> <div id="divTreeSearchResult"> @if(Model.TreeResultObj != null) { resultHtml = Html.ContentFromPartial("_TreeReport", Model.TreeResultObj); @Html.Raw(resultHtml); -- Not working @Html.Raw(HttpUtility

MVC 5 Date Format is displaying as MM/dd/yyyy in Edit when I want dd/MM/yyyy

a 夏天 提交于 2019-12-13 23:00:47
问题 I know this is an old problem that has been answered many times but I have searched for several months without solving my problem. My app is local only and needs to be en AU. I am a newbe and answers I have found relate to a global file which MVC 5 does not have so am thoroughly confused (I assume I use Startup.cs ??). Don't know whether I need a custom route or a custom model binder. Model { public partial class SuspensionHist { [Key] [Column(Order = 0)] public int AssociId { get; set; }

Change display format number decimal separator

岁酱吖の 提交于 2019-12-13 22:22:37
问题 I have the following float number : -95.83334 this is in my view model: [DisplayFormat(DataFormatString = "{0:#.##}")] public float? mx { get; set; } this is in my view @Html.HiddenFor(model => model.mx) this is the generated html <input data-val="true" id="mx" name="mx" type="hidden" value="-95,83334"> and this is the desired html <input data-val="true" id="mx" name="mx" type="hidden" value="-95.83334"> so the question is, which is the best way to change the decimal separator for this hidden

Get UserName by UserId and display in View

只谈情不闲聊 提交于 2019-12-13 22:15:10
问题 In an ASP.NET MVC 5 application how would I go about getting a Username from a given UserId and display it in a View ? Note - I do not need the Username of the current User . 回答1: Based on your comment, you are using ASP.Net Identity. I assume you already have ApplicationUserManager. For example, private ApplicationUserManager _userManager; protected ApplicationUserManager UserManager { get { return _userManager ?? (_userManager = HttpContext.GetOwinContext().GetUserManager

How to get {ID} in url “controller/action/id” in a post action?

[亡魂溺海] 提交于 2019-12-13 21:59:45
问题 In the cshtml file, I have the following javascript in Home/Details/4 . 4 is the ID. <script> $(document).ready(function () { $("#checkbox").click(function () { $.post( "Home/Toggle", { checkbox: $("#checkbox").val() }, function (data) { }); }); }); </script> The following is the action code in the controller. [HttpPost] [ValidateAntiForgeryToken] public ActionResult Toggle(bool checkbox) { ...... // How to get ID? var x = db.XXXX.Find(id); How to get the ID? From some routing data, or Url,

ASP.Net MVC 5 Html.BeginForm onsubmit and model with required attribute

天大地大妈咪最大 提交于 2019-12-13 21:34:57
问题 I have required attribute on my model properties but I added a "spinner" to show processing request in form onsubmit. Now, even though that it didn't submit the form, it shows the "spinner" i created, and stuck on the overlay but the textbox with required attribute is in focus. using (Html.BeginForm("Add", "UserAccount", FormMethod.Post, new { onsubmit="spinner()"})) { //Html.TextBoxes for model properties with required } <div id="spinner" hidden=""> <div> <i class="fa fa-spinner fa-spin fa

All radio buttons are grouped together for all the items in the model list

£可爱£侵袭症+ 提交于 2019-12-13 20:03:29
问题 I am using MVC5 Situation: my view iterates through a list of Person class where the properties are as follow: int Id string Name string City string ChosenText List<string> SomeTextList This list of string would be randomly generated strings. while iterating through the list all the SomeTextList should be shown as radio button. Hence for every person all there are: one textbox for name one textbox for City group of radio button for SomeTextList The code is : @foreach (var item in Model) {

Insert view with collection property

筅森魡賤 提交于 2019-12-13 19:17:58
问题 I have a Person class and a Contact class. A person can have many contacts. public class Person { [Required] public string FirstName { get; set; } public string LastName { get; set; } public string Notes { get; set; } [Required] public List<Contact> Contacts { get; set; } public Person() { Contacts = new List<Contact>(); } } public class Contact { [Required] public string Title { get; set; } [Required] public string Value { get; set; } public Contact() { Title = ""; Value = ""; } public

MvcHtmlString with Razor statements included

好久不见. 提交于 2019-12-13 18:27:28
问题 I find myself repeating this code block too often... <div class="form-group"> <div class="col-sm-3 control-label"> @Html.LabelFor(m => m.Name) </div> <div class="col-sm-9"> @Html.TextBoxFor(m => m.Name, null, new { @class = "form-control" }) @Html.ValidationMessageFor(m => m.Name) </div> </div> I have been attempting to create a MvcHtmlString custom extension, but it assumes that the @Html.LabelFor commands are text and that is what is displayed. EDIT: Thanks Joe and Stephen!! That's what I

Ninject - Injecting singleton

*爱你&永不变心* 提交于 2019-12-13 18:23:17
问题 I have this error when clicking a link on a site I'm creating Error activating IEntityCache using binding from IEntityCache to EntityCache No constructor was available to create an instance of the implementation type. Activation path: 4) Injection of dependency IEntityCache into parameter entityCache of constructor of type AlbumRepository 3) Injection of dependency IAlbumRepository into parameter albumRepository of constructor of type AlbumService 2) Injection of dependency IAlbumService into