razor

Action Image MVC3 Razor

佐手、 提交于 2019-12-17 02:27:29
问题 What is the best way to replace links with images using Razor in MVC3. I simply doing this at the moment: <a href="@Url.Action("Edit", new { id=MyId })"><img src="../../Content/Images/Image.bmp", alt="Edit" /></a> Is there a better way? 回答1: You can create an extension method for HtmlHelper to simplify the code in your CSHTML file. You could replace your tags with a method like this: // Sample usage in CSHTML @Html.ActionImage("Edit", new { id = MyId }, "~/Content/Images/Image.bmp", "Edit")

MVC Razor view nested foreach's model

人走茶凉 提交于 2019-12-17 02:27:05
问题 Imagine a common scenario, this is a simpler version of what I'm coming across. I actually have a couple of layers of further nesting on mine.... But this is the scenario Theme contains List Category contains List Product contains List My Controller provides a fully populated Theme, with all the Categories for that theme, the Products within this categories and the their orders. The orders collection has a property called Quantity (amongst many others) that needs to be editable. @model

How to use jquery or ajax to update razor partial view in c#/asp.net for a MVC project

泄露秘密 提交于 2019-12-17 02:21:34
问题 In a MVC partial view file, I build one Html.TextBox and two submit buttons. These two buttons will increase/decrease the Html.TextBox value once clicked. The Html.TextBox displayed value will change accordingly.However, once I need to update the #refTable div based on the new value after click. The page or section never updated. Codes are below, where some comments are added for explanation purpose. Thanks for your help. // * ** * *** cshtml file ** * ** * **** // <body> </body> <input type=

How do I write unencoded Json to my View using Razor?

寵の児 提交于 2019-12-16 22:45:06
问题 I'm trying to write an object as JSON to my Asp.Net MVC View using Razor, like so: <script type="text/javascript"> var potentialAttendees = @Json.Encode(Model.PotentialAttendees); </script> The problem is that in the output the JSON is encoded, and my browser doesn't like it. For example: <script type="text/javascript"> var potentialAttendees = [{"Name":"Samuel Jack"},]; </script> How do I get Razor to emit unencoded JSON? 回答1: You do: @Html.Raw(Json.Encode(Model.PotentialAttendees)) In

Pass List of Checkboxes into View and Pull out IEnumerable [duplicate]

喜欢而已 提交于 2019-12-16 18:50:13
问题 This question already has answers here : How does MVC 4 List Model Binding work? (5 answers) Closed 4 years ago . I have a list of items that will be associated to a user. It's a one-to-many relationship. I want the entire list of items passed into the view so that they can choose from ones that are not associated to them yet (and also see those that are already associated). I want to create checkboxes from these. I then want to send the selected ones back into the controller to be associated

Pass List of Checkboxes into View and Pull out IEnumerable [duplicate]

拥有回忆 提交于 2019-12-16 18:50:12
问题 This question already has answers here : How does MVC 4 List Model Binding work? (5 answers) Closed 4 years ago . I have a list of items that will be associated to a user. It's a one-to-many relationship. I want the entire list of items passed into the view so that they can choose from ones that are not associated to them yet (and also see those that are already associated). I want to create checkboxes from these. I then want to send the selected ones back into the controller to be associated

你为什么要使用表达 <Func<T> >而不是Func <T> ?

Deadly 提交于 2019-12-15 21:11:06
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我了解lambda和 Func 和 Action 代表。 但是表情让我难过。 在什么情况下,您将使用 Expression<Func<T>> 而不是普通的旧 Func<T> ? #1楼 我想添加一些关于 Func<T> 和 Expression<Func<T>> 之间的区别的注释: Func<T> 只是一个普通的老式MulticastDelegate; Expression<Func<T>> 以表达式树的形式表示lambda表达式; 表达式树可以通过lambda表达式语法或API语法构造; 表达式树可以编译为委托 Func<T> ; 从理论上讲,逆转换是可能的,但是这是一种反编译,因为它不是一个简单的过程,所以没有内置功能; 可以通过 ExpressionVisitor 观察/翻译/修改表达树; IEnumerable的扩展方法与 Func<T> ; IQueryable的扩展方法使用 Expression<Func<T>> 。 有一篇文章描述了代码示例的详细信息: LINQ:Func <T>与Expression <Func <T >> 。 希望对您有所帮助。 #2楼 主要原因是当您不想直接运行代码,而是想对其进行检查时。 这可能有多种原因: 将代码映射到其他环境(即,将C#代码映射到Entity

Embedding Razor views in class library as resources

泄露秘密 提交于 2019-12-14 04:27:28
问题 I'm using VirtualPathProvider to provide themed views. In action method I want to return a view by path return View("~/Themes/SomeTheme.dll/Views/Content/Item.cshtml"); In Visual Studio Item.cshtml has a build action "Embedded Resource". VirtualPathProvider finds that .cshtml file, but I get an error The view at '~/Themes/SomeTheme.dll/Views/Content/Item.cshtml' must derive from WebViewPage, or WebViewPage<TModel>. I guess I have to compile that view and I've followed these instructions. Now

How do I add a querystring when using the MVC PagedList?

柔情痞子 提交于 2019-12-14 04:08:07
问题 How would I go about adding a query string to the Razor Helper PagedListPager below ? @Html.PagedListPager( (IPagedList)Model.PartsList, page => Url.Action("Index", new { page }) ) 回答1: You don't add query parameters in PagedListPager , you do them in Url.Action . Below is an updated version of your code, I've added a query parameter tag . Url.Action("Index", new { page, tag = 'asp' }) The URL would generate the following query string ?page=1&tag=asp Here is the same Url.Action within

Custom Assembly Attribute to String

半世苍凉 提交于 2019-12-14 04:07:27
问题 I have defined a custom assembly attribute and am trying to call it into a string much like my previous post Calling Custom Assembly Attributes. I am now trying to accomplish the very same thing in c#. I have defined my custom attribute: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Reflection; namespace authenticator.Properties { public class SemverAttribute : Attribute { private string _number; public