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

242 Views Asked by At

It is possible to use Polymer library with Strongly-Typed View in a ASP.NET MVC project?

Or...I can use custom elements and Razor but the Polymer Library is too big.

Is there any other way?

1

There are 1 best solutions below

0
SG Alunos On

You can use Polymer library without use an element created by 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:

> 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

>

 <!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. 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. The action Products must have the seme name of your elements in .cshtml. This way you can get the information of any HTML, Polymer or other elemets.

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