2016-04-09 8 views

cevap

0

Polimer kitaplığını, Razor tarafından oluşturulan bir öğeyi kullanmadan kullanabilirsiniz. Ben basit öğelerle sınamak ama sizin için çalışacaktır düşünüyorum: nihayet

> 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(); 
>   } 
> } 

Ve .cshtml:

Bir sınıf Ürün

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

Ve 2 eylemlerle benim Kontrolörü vardı Eğer yuor elemanları koyacağız

>

<!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> 

Eyleminin/Home/Products'a yönlendirildiği bir formum var. Gönderinizde, form, Ürünlerinizi, dosyalarınızı kendilerine verdiğiniz ilgili adla geçirerek gerçekleştirecektir. .cshtm'de "ad", "fiyat", "qtd". Ürünlerin, öğelerinizin .shtml cinsinden seme adının olması gerekir. Bu şekilde herhangi bir HTML, Polimer veya diğer elemelerin bilgilerini alabilirsiniz.

Bonus, bu şekilde aynı sonucu elde edebilirsiniz:

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

Ve Eylem

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