簡體   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