繁体   English   中英

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

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

是否可以在ASP.NET MVC项目中将聚合物库与强类型视图一起使用?

或者...我可以使用自定义元素和Razor,但Polymer Library太大。

还有其他办法吗?

您可以使用Polymer库,而无需使用Razor创建的元素。 我测试了简单的元素,但我认为它将对您有用:

我有一个班级产品

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

我的控制器有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();
>         }
> }

最后是.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>

我有一个表单,其操作直接针对/ Home / Products。 提交时,表单将调用您的“产品”操作,并以您提供给他们的相应名称来传递您的字段。 .cshtm中的“名称”,“价格”,“ qtd”。 “产品”操作必须在.cshtml中具有元素的名称。 这样,您可以获得任何HTML,Polymer或其他要素的信息。

奖励,您可以通过以下方式获得相同的结果:

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

和动作

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM