razor

Javascript, Razor and Escape characters. Like apostrophe

一曲冷凌霜 提交于 2019-12-17 10:33:42
问题 I am using Razor in my MVC3 project. And also I'm using FullCalendar JQuery plugin. So when I'm trying to fill the array it works good. Except one thing. If s.Name contains apostrophe it renders like ' that's not what I want. I tried to use different methods like Encode and Decode and even MvcHtmlString.Create and result is always the same. Here is the code snippet: <head> <script type='text/javascript'> $(document).ready(function () { $('#calendar').fullCalendar({ header: { left: '', center:

The view must derive from WebViewPage, or WebViewPage<TModel>

孤街醉人 提交于 2019-12-17 10:18:33
问题 I'm following Justin Slattery's Plugin Architecture tutorial and trying to adapt it for Razor, instead of WebForm Views. Everything else (controllers, plugin assembly loading, etc) seems to be okay. However, I'm not able to get embedded Razor views to work properly. When I try to browse to the "HelloWorld/Index", I get the following error: The view at '~/Plugins/MyProjectPlugin.dll/MyProjectPlugin.Views.HelloWorld.Index.cshtml' must derive from WebViewPage or WebViewPage<TModel>. The

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key “key”

时间秒杀一切 提交于 2019-12-17 10:02:16
问题 My code is like this namespace DiagnosisApp.Models { public class ProcedurePrice { public int ID { get; set; } public int DepartmentID { get; set; } public int ProcedureID { get; set; } public int InsuranceProviderID { get; set; } public int ProcedureCategoryID { get; set; } public int ProcedureSubCategoryID { get; set; } [ForeignKey("ID")] public virtual Department Department { get; set; } [ForeignKey("ID")] public virtual InsuranceProvider InsuranceProvider { get; set; } [ForeignKey("ID")]

How to retain spaces in DropDownList - ASP.net MVC Razor views

陌路散爱 提交于 2019-12-17 09:21:37
问题 I'm binding my model in the following way in the view: <%=Html.DropDownList("SelectedItem",new SelectList(Model.MyItems,"ItemId","ItemName")) %> Issue is my item text is a formatted text with spaces in between words, as below. #123 First $234.00 #123 AnotherItem $234.00 #123 Second $234.00 I want to retain the spaces in this item text even after they are added to DropDownList. But unfortunately my DropDownList shows them without spaces as below: #123 First $234.00 #123 AnotherItem $234.00

How to retain spaces in DropDownList - ASP.net MVC Razor views

跟風遠走 提交于 2019-12-17 09:21:19
问题 I'm binding my model in the following way in the view: <%=Html.DropDownList("SelectedItem",new SelectList(Model.MyItems,"ItemId","ItemName")) %> Issue is my item text is a formatted text with spaces in between words, as below. #123 First $234.00 #123 AnotherItem $234.00 #123 Second $234.00 I want to retain the spaces in this item text even after they are added to DropDownList. But unfortunately my DropDownList shows them without spaces as below: #123 First $234.00 #123 AnotherItem $234.00

How to display an image from a path in asp.net MVC 4 and Razor view?

我的未来我决定 提交于 2019-12-17 08:55:15
问题 I have the following model: public class Player { public String ImagePath { get { return "~/Content/img/sql_error.JPG"; } } And, this is my .cshtml file: @model SoulMasters.Models.Game.Player @{ ViewBag.Title = "Game"; Layout = "~/Views/Shared/_GameLayout.cshtml"; var imagePath = @Model.ImagePath; } <fieldset> <legend>Player</legend> <div class="display-field"> @Html.DisplayFor(model => model.ImagePath) </div> @imagePath <div style="padding:10px;"> <img src=@imagePath alt="Sample Image" width

Adding a css class to select using @Html.DropDownList()

会有一股神秘感。 提交于 2019-12-17 07:16:09
问题 I'm building my first MVC application after years of doing webforms, and for some reason I am not able to make this work: @Html.DropDownList("PriorityID", String.Empty, new {@class="textbox"} ) Error message: System.Web.Mvc.HtmlHelper<SPDR.Models.Bug> ' does not contain a definition for DropDownList and the best extension method overload System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper, string, System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>,

Adding a css class to select using @Html.DropDownList()

本小妞迷上赌 提交于 2019-12-17 07:16:01
问题 I'm building my first MVC application after years of doing webforms, and for some reason I am not able to make this work: @Html.DropDownList("PriorityID", String.Empty, new {@class="textbox"} ) Error message: System.Web.Mvc.HtmlHelper<SPDR.Models.Bug> ' does not contain a definition for DropDownList and the best extension method overload System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper, string, System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>,

Calling ASP.NET MVC Action Methods from JavaScript

隐身守侯 提交于 2019-12-17 07:13:22
问题 I have sample code like this: <div class="cart"> <a onclick="addToCart('@Model.productId');" class="button"><span>Add to Cart</span></a> </div> <div class="wishlist"> <a onclick="addToWishList('@Model.productId');">Add to Wish List</a> </div> <div class="compare"> <a onclick="addToCompare('@Model.productId');">Add to Compare</a> </div> How can I write JavaScript code to call the controller action method? 回答1: Use jQuery ajax: function AddToCart(id) { $.ajax({ url: 'urlToController', data: {

Can I serve .html files using Razor as if they were .cshtml files without changing the extension of all my pages?

隐身守侯 提交于 2019-12-17 06:45:21
问题 I manage a large asp.net site which has previously been converted from static html site to asp.net. For several reasons (mainly SEO) we decided not to rename all the files to .aspx back when we originally converted the site. This was very easy to do by simply adding the buildProvider and httpHandler to the web.config. <buildProviders> <add extension=".html" type="System.Web.Compilation.PageBuildProvider"/> </buildProviders> <httpHandlers> <add path="*.html" verb="*" type="System.Web.UI