razor

How do ASP.NET Core's “asp-fallback-*” CDN tag helpers work?

只谈情不闲聊 提交于 2019-12-18 04:36:22
问题 I understand what the asp-fallback-* tag helpers do. What I don't understand is how. For example: <link rel="stylesheet" href="//ajax.aspnetcdn.com/ajax/bootstrap/3.3.5/css/bootstrap.min.css" asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css" asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" /> This loads bootstrap from the CDN, and loads the local copy if the CDN is down. But how does it decide to do that? I assume it

How to get claim inside Asp.Net Core Razor View

让人想犯罪 __ 提交于 2019-12-18 04:34:32
问题 I did it in my rc1 project like: User.Claims.ElementAt(#).Value But after I switched to rtm it wouldn’t work anymore. When I debug the Razor view the object looks the same but User.Claims is just empty. Any idea what the reason could be. 回答1: Assuming you have claims attached to the current principal. In your Razor view: @((ClaimsIdentity) User.Identity) This will give you access to the ClaimsIdentity of the current user. In an effort to keep your claims fetching clean you may want to create

Load Razor view from db, but ViewBag is broken

旧街凉风 提交于 2019-12-18 04:18:12
问题 I'm pulling a razor view's markup from the database, as detailed in this question: ASP.NET MVC load Razor view from database I can pull the view, but it fails on execution because ViewBag is not recognized. CS0103: The name 'ViewBag' does not exist in the current context Any suggestions? Here's the source: global: protected void Application_Start() { AreaRegistration.RegisterAllAreas(); System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(new BearForce.Web.Core.DbPathProvider());

Bind Enum with dropdown and set selected value on get action in MVC C#

ε祈祈猫儿з 提交于 2019-12-18 04:18:11
问题 I have a Enum called CityType public enum CityType { [Description("Select City")] Select = 0, [Description("A")] NewDelhi = 1, [Description("B")] Mumbai = 2, [Description("C")] Bangalore = 3, [Description("D")] Buxar = 4, [Description("E")] Jabalpur = 5 } Generate List from Enum IList<SelectListItem> list = Enum.GetValues(typeof(CityType)).Cast<CityType>().Select(x => new SelectListItem(){ Text = EnumHelper.GetDescription(x), Value = ((int)x).ToString() }).ToList(); int city=0; if (userModel

How can I create more than one editor template for a multi-line textbox in MVC3?

倾然丶 夕夏残阳落幕 提交于 2019-12-18 04:09:28
问题 I have the following two types of multiline textareas in my views: <textarea cols="100" rows="15" class="full-width" id="dialogText" name="Text">@Model.Text</textarea> <textarea cols="100" rows="10" class="full-width" id="dialogText" name="Text">@Model.Text</textarea> I would like to take advantage of custom editor templates, but keep the ability to specify attributes differently (e.g. the rows are different between the two above). Is it possible for me to declare and use two different kinds

Using the Razor view engine in a different way

雨燕双飞 提交于 2019-12-18 03:55:46
问题 I thought it would be interesting if I could use the new MVC Razor View engine as a mail merge technology. It can still be part of an MVC website and does not have to be stand-alone console app. Example: string myTemplate = "Hello @Name, How are you today?"; ViewModel.Name = "Billy Boy"; string output = RazorViewEngineRender( myTemplate, ViewModel ); Then the string output = "Hello Billy Boy, How are you today?" The main thing is I want the template to be driven from a string rather than a

Using Html instead of csHtml

二次信任 提交于 2019-12-18 03:55:19
问题 I want to use pure html page instead of cshtml with MVC .net. But when I add view by right clicking Index i can see only two options. public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { return View(); }} Cshtml (Razor) Aspx I followed Can I serve .html files using Razor as if they were .cshtml files without changing the extension of all my pages? forum but still no help. I still don’t see an option to add html instead of cshtml I also tried adding html

Razor DropDownListFor: Adding Extra Attribute To SelectList Option Tag

China☆狼群 提交于 2019-12-18 03:44:46
问题 I'm trying to create a select list. I've created it just fine using a collection from my viewmodel that allows me to set each option's value and text with the following code: @Html.DropDownListFor(model => model.Networks, new SelectList(Model.Networks, "NetworkID", "Name"), new { @class="form-control" }) Model.Networks contains another property called CountryId. I'd like to add an attribute to each option tag so it looks like: <option value="[NetworkId]" data-countryId="[CountryId]">Canada<

create ajax actionlink with html elements in the link text

血红的双手。 提交于 2019-12-18 03:42:26
问题 I would like to convert a link to an ajax action link. I can't figure out how to display html elements within the link text? Here is the original link: <a href="#onpageanchor" id="myId" class="myClass" title="My Title."><i class="icon"></i>Click Me</a> Here is the ajax actionlink: @Ajax.ActionLink("<i class='icon'></i>Click Me", "MyActionMethod", new { id = "testId" }, new AjaxOptions { UpdateTargetId = "mytargetid" }, new { id = "myId", @class = "myClass", title="My Title." }) the link text

How can I refresh just a Partial View in its View?

安稳与你 提交于 2019-12-18 03:40:17
问题 What Am I doing wrong guys? This is the idea... Index view <div class="col-lg-12 col-md-12 col-xs-12"> @Html.Partial("PartialView", Model) </div> Controller public ActionResult PartialView() { return PartialView("PartialView"); } [HttpPost, ValidateInput(false)] public ActionResult POSTPartialView(string param1) { return PartialView("PartialView"); } PartialView has a Form. The first time I enter in Index, PartialView works, but the second time, after a POST call (coming from the form inside