简体   繁体   English

如何将聚合物库与强类型视图一起使用?

[英]How can i use Polymer library with Strongly-Typed View?

It is possible to use Polymer library with Strongly-Typed View in a ASP.NET MVC project? 是否可以在ASP.NET MVC项目中将聚合物库与强类型视图一起使用?

Or...I can use custom elements and Razor but the Polymer Library is too big. 或者...我可以使用自定义元素和Razor,但Polymer Library太大。

Is there any other way? 还有其他办法吗?

You can use Polymer library without use an element created by Razor. 您可以使用Polymer库,而无需使用Razor创建的元素。 I test with simple elements but I think it will work for you: 我测试了简单的元素,但我认为它将对您有用:

I had a class Product 我有一个班级产品

public class Product
    {
        public string Name { get; set; }
        public float Price { get; set; }
        public float Qtd { get; set; }
    }

And my Controller with 2 actions: 我的控制器有2个动作:

> public class HomeController : Controller 
>{
>         //
>         // GET: /Home/
>         public ActionResult Index()
>         {
>             return View();
>         }
> 
>         public ActionResult Products(string name, float price, int qtd)
>         {
>             Product product = new Product();
> 
>             product.Name = name;
>             product.Price = price;
>             product.Qtd = qtd;
> 
>             return View();
>         }
> }

And finaly the .cshtml when you will put yuor elements 最后是.cshtml,何时放置您的元素

> >

 <!DOCTYPE html>
> 
> <html> 
> <head>
>     <meta name="viewport" content="width=device-width" />
>     <title>Produtos</title> </head> <body>
>     <div>
>         <form action="/Home/Products">
>             <label>Name</label>
>             <input type="text" name="name" />
> 
>             <label>Price</label>
>             <input type="number" name="price" />
> 
>             <label>Qtd</label>
>             <input type="number" name="qtd" />
> 
>             <input type="submit" value="Insert" />
>         </form>
>     </div> 
></body> 
></html>

I have a form where its action is directed to /Home/Products. 我有一个表单,其操作直接针对/ Home / Products。 When you submit, the form will call your Products action passing your filds by respective name you gave to them. 提交时,表单将调用您的“产品”操作,并以您提供给他们的相应名称来传递您的字段。 "name", "price", "qtd" in the .cshtm. .cshtm中的“名称”,“价格”,“ qtd”。 The action Products must have the seme name of your elements in .cshtml. “产品”操作必须在.cshtml中具有元素的名称。 This way you can get the information of any HTML, Polymer or other elemets. 这样,您可以获得任何HTML,Polymer或其他要素的信息。

Bonus, you can get the same result in this way: 奖励,您可以通过以下方式获得相同的结果:

  <input type="text" name="product.Name" /> <input type="number" name="product.Price" /> <input type="number" name="product.Qtd" /> 

And the Action 和动作

> public ActionResult Products(Product product)
>         {
>             return View();
>         }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在服务器标签中使用强类型资源? - How can I use strongly-typed resources in server tags? 如何在启动 class 中使用强类型配置 - How can I use a strongly-typed config within the Startup class 如何使用强型卫星组件? - How to use strongly-typed satellite assembly? 强类型视图未初始化? - Strongly-typed view not initializing? 易于使用的强类型JSON库用于C# - Easy to use strongly-typed JSON library for C# Objective-C转换为C#:如果字典是强类型的,如何在C#中使用多个类型的.plist? - Objective-C converting to C#: How can I use a .plist with multiple types in C# if Dictionary is strongly-typed? 我无法在Visual Studio 2015中向MVC项目添加强类型视图 - I can't add a strongly-typed view to MVC project in Visual Studio 2015 我可以使用什么强类型数据结构来保存具有不同形状的多个RecordSet的集合 - What Strongly-Typed Data-Structure can I use to hold a collection of multiple RecordSets with different shape 我可以使用什么数据结构来表示.Net中的强类型2D数据矩阵? - What data structures can I use to represent a strongly-typed 2D matrix of data in .Net? 使用ServiceStack.Redis,如何在事务中运行强类型的只读查询 - Using ServiceStack.Redis, how can I run strongly-typed read-only queries in a transaction
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM