[英]How can i use Polymer library with Strongly-Typed View?
It is possible to use Polymer library with Strongly-Typed View in a ASP.NET MVC project? 是否可以在ASP.NET MVC项目中将聚合物库与强类型视图一起使用?
Or...I can use custom elements and Razor but the Polymer Library is too big. 或者...我可以使用自定义元素和Razor,但Polymer Library太大。
Is there any other way? 还有其他办法吗?
You can use Polymer library without use an element created by Razor. 您可以使用Polymer库,而无需使用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: 我的控制器有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();
> }
> }
And finaly the .cshtml when you will put yuor elements 最后是.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>
I have a form where its action is directed to /Home/Products. 我有一个表单,其操作直接针对/ 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. .cshtm中的“名称”,“价格”,“ qtd”。 The action Products must have the seme name of your elements in .cshtml. “产品”操作必须在.cshtml中具有元素的名称。 This way you can get the information of any HTML, Polymer or other elemets. 这样,您可以获得任何HTML,Polymer或其他要素的信息。
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();
> }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.