2016-04-09 39 views

回答

0

您可以在不使用由Razor創建的元素的情況下使用Polymer庫。我測試用簡單的元素,但我認爲它會爲你工作:

我有一類產品

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

而且finaly的.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,聚合物或其他元素的信息。

獎金,你可以通過這種方式獲得相同的結果:

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