razor

How to concatenate two strings in image source with razor?

你。 提交于 2020-01-15 12:43:07
问题 I've defined the following variable in razor: @{string imageRoot = "/_media/Images/";} I'd like to use it here: <img src="@imageRoot App1/MyImage.png"/> The problem is the space within the string. This will work but I'd like to keep the trailing slash in the variable instead of in the literal: @{string imageRoot = "/_media/Images";} <img src="@imageRoot/App1/MyImage.png"/> 回答1: Looks a little ugly, but works: @{string imageRoot = "/_media/Images/";} <img src="@Html.Raw(imageRoot)App1/MyImage

How do I use @Url.Content() in non-MVC Razor webpage?

淺唱寂寞╮ 提交于 2020-01-15 12:14:28
问题 Since I'm using Web Application having NuGet Package's Microsoft.AspNet.Razor installed. In WebForm pages ( .aspx), I can use ResolveUrl() but in Razor pages ( .cshtml), I get this error --> "x:\Source\Foo.Dealer\Foo.Dealer.WebApp.Mobile\Member\DmsDashboard.cshtml(103): error CS0103: The name 'Url' does not exist in the current context" Source-Code here.. @section HeadJavascriptLibraryFile { <script type="text/javascript" src="@Url.Content("~/scripts/webpages/setting-dmsdashboard.js")"><

How do I access data in a view in Razor?

為{幸葍}努か 提交于 2020-01-15 10:54:36
问题 In standard WebForms, I would have a handful of properties, and set those. Then the Web Page would bind to them, for example with <%#CustomerName%> . I understand that MVC is a different approach, but there must still be a basic need for displaying data from multiple sources at the same time. I can see that if I use @Model then it will access the data set in the controller. But what if You want to display data from 2 or 3 separate items? If I want to display a Customer , their address and

How do I access data in a view in Razor?

自闭症网瘾萝莉.ら 提交于 2020-01-15 10:53:44
问题 In standard WebForms, I would have a handful of properties, and set those. Then the Web Page would bind to them, for example with <%#CustomerName%> . I understand that MVC is a different approach, but there must still be a basic need for displaying data from multiple sources at the same time. I can see that if I use @Model then it will access the data set in the controller. But what if You want to display data from 2 or 3 separate items? If I want to display a Customer , their address and

How do I access data in a view in Razor?

廉价感情. 提交于 2020-01-15 10:53:34
问题 In standard WebForms, I would have a handful of properties, and set those. Then the Web Page would bind to them, for example with <%#CustomerName%> . I understand that MVC is a different approach, but there must still be a basic need for displaying data from multiple sources at the same time. I can see that if I use @Model then it will access the data set in the controller. But what if You want to display data from 2 or 3 separate items? If I want to display a Customer , their address and

How do I access data in a view in Razor?

跟風遠走 提交于 2020-01-15 10:53:24
问题 In standard WebForms, I would have a handful of properties, and set those. Then the Web Page would bind to them, for example with <%#CustomerName%> . I understand that MVC is a different approach, but there must still be a basic need for displaying data from multiple sources at the same time. I can see that if I use @Model then it will access the data set in the controller. But what if You want to display data from 2 or 3 separate items? If I want to display a Customer , their address and

BeginForm with IEnumerable

老子叫甜甜 提交于 2020-01-15 10:51:10
问题 I have the following view: @model IEnumerable<YIS2.Models.Testimonial> @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } <div id="Testimonials"> <h2>Our Testimonials</h2> @foreach (var item in Model) { <blockquote> <p>@item.Content</p> <p>@item.AuthorName</p> </blockquote> } </div> <div id="SubmitTestimonial"> <h2>Submit Testimonial</h2> @using (Html.BeginForm("NewTestimonial", "Testimonial", FormMethod.Post)) { @Html.EditorFor(m => Model.AuthorName) @Html.EditorFor(m =>

BeginForm with IEnumerable

心已入冬 提交于 2020-01-15 10:51:04
问题 I have the following view: @model IEnumerable<YIS2.Models.Testimonial> @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } <div id="Testimonials"> <h2>Our Testimonials</h2> @foreach (var item in Model) { <blockquote> <p>@item.Content</p> <p>@item.AuthorName</p> </blockquote> } </div> <div id="SubmitTestimonial"> <h2>Submit Testimonial</h2> @using (Html.BeginForm("NewTestimonial", "Testimonial", FormMethod.Post)) { @Html.EditorFor(m => Model.AuthorName) @Html.EditorFor(m =>

Convert webform control to Razor syntax

不羁的心 提交于 2020-01-15 10:44:45
问题 i got this control and it works fine, but i need to use it on my mvc3 project. I tryed my way but didnt work. I hope someone can help me. Thats the webform custom control code: ASPX: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="BoletoCS.aspx.cs" Inherits="BoletoCS" %> <%@ Register Assembly="Impactro.Cobranca" Namespace="Impactro.WebControls" TagPrefix="cob" %> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>Boleto</title> <style type="text/css">

MVC3 Razor JQuery client side validation with an additional alert box

霸气de小男生 提交于 2020-01-15 10:15:49
问题 I am being asked to create a login form that when the user input doesn't pass validation it pops an alert box. I have everything wire up using the model based validation. ex: public class LogonViewModel { [Required( ErrorMessage = "User Name is Required")] public string UserName { get; set; } [Required( ErrorMessage = "Password is required")] public string Password { get; set; } } I have a validation summary on the page: Html.ValidationSummary() I would like the summary to be on the page just