MVC2:正在渲染 List
我有这个模型:
public class Package
{
public string CustomerName { get; set; }
public List<Product> Products { get; set; }
}
public class Product
{
public int Quantity { get; set; }
public string Name { get; set; }
}
当我添加创建视图时,代码是:
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.CustomerName) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.CustomerName) %>
<%: Html.ValidationMessageFor(model => model.CustomerName) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
如何管理产品列表? 我可以获得一个按钮或其他东西来创建新产品并将其添加到产品列表中吗?
谢谢
I have this Model:
public class Package
{
public string CustomerName { get; set; }
public List<Product> Products { get; set; }
}
public class Product
{
public int Quantity { get; set; }
public string Name { get; set; }
}
When I add the Create's view, the code is:
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.CustomerName) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.CustomerName) %>
<%: Html.ValidationMessageFor(model => model.CustomerName) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
How manage the Products list?
Can I get a button or something to create a new product and add it to the Products list?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要创建按钮,您还可以使用 HTML.ActionLink() 或 Ajax.ActionLink() 定义为按钮,例如:
它将在您的页面上创建一个按钮,在这里您可以看到不同的属性(因此只需检查它们即可)会发现它很有用)...并且从这两个方面来看,使用哪个更多取决于您想要的操作...
并且在您的控制器中:
这里是示例:模式弹出窗口,声明为页面的部分视图
[使用 Ajax.ActionLink() 的部分视图]
您的部分视图操作:
for creating buttn you can also do this use HTML.ActionLink() or Ajax.ActionLink() defined as a button like:
it'll create a button on your page, and here you can see different attributes (so just check them out you'll find it useful) ... and from both of this which to use is more depends upon your desired action ...
and in your controller:
here is the example: modal popup, declared as a partial view of page
[partial view using Ajax.ActionLink()]
your partial view action:
刚刚输入此内容,尚未对其进行测试,但基本思想是在客户视图上列出您的产品,并使用一个按钮为客户添加新产品。
列出客户的产品:
要为客户添加新产品,您可以使用 jQuery UI 显示一个对话框;只需传递客户 ID
包含 jquery-ui
// 假设您已在产品控制器中
返回部分_Create 视图
Just typed this up, haven't tested it but the basic idea is to list your products on the customer view with a button to add a new product for a customer.
To list Products for Customer:
To add a new Product for a customer you could use jQuery UI to show a dialog; just pass the Customer Id
// assuming you've included jquery-ui
In your product controller return a partial
_Create view