0
嗨夥計我必須創建一個共享內容頁面,我有一個contentitem可以共享,共享它的用戶以及他想要共享的ppl的接收者,但是我想這樣做動態的,這是我的域模型如何用對象列表創建多個文本框
public class ShareContentItemModel : BaseModel
{
public ContentItem ContentItem { get; set; }
public User User { get; set;}
[Display(Name = "Recipients")]
public List<Recipient> Recipients { get { return new List<Recipient> { new Recipient { Name = "Recipient name here", Email = "Write Recipient Email here" } }; } }
[Required]
[Display(Name = "Nachricht")]
public string Message { get; set; }
}
public class Recipient{
[Display(Name = "Recipient Name:")]
public string Name { get; set;}
[Display(Name = "Recipient Email Address:")]
public string Email { get; set;}
}
,這是我的看法
@using (Html.BeginForm("Submit", "Contact", FormMethod.Post))
{
<p>Hi: @Html.DisplayTextFor(m=>m.User.Salutation) @Html.DisplayTextFor(m=>m.User.Firstname) @Html.DisplayTextFor(m=>m.User.Lastname)</p>
<table border="0" style="padding:5">
<tr>
<td class="editor-label">@Html.LabelFor(m => m.ContentItem.Title): </td>
<td class="editor-field">@Html.DisplayTextFor(m => m.ContentItem.Title)
<div>@Html.ValidationMessageFor(m => m.ContentItem.Title)</div>
</td>
</tr>
<tr>
<td class="editor-label">@Html.LabelFor(m => m.ContentItem.Description): </td>
<td class="editor-field">@Html.DisplayTextFor(m => m.ContentItem.Description)
<div>@Html.ValidationMessageFor(m => m.ContentItem.Title)</div>
</td>
</tr>
<tr><td colspan="2">Recipients:</td></tr>
@foreach (var item in @Model.Recipients)
{
<tr>
<td>@item.Name: @Html.TextBoxFor(/*Dont know what to put in here*/)</td>
<td>@item.Email: @Html.TextBoxFor(/*Dont know what to put in here*/) </td>
</tr>
}
<tr>
<td> <a class="small button" href="#">Add Recipient:</a> </td>
<td><input type="submit" class="button med primary" style="float: right;" value="ABSENDEN" /></td>
</tr>
</table>
}
,你可以在//不要看看就知道要放什麼東西在這裏 我不能使用item.name或item.email屬性可以幫助我這個
p.d.該對象是罰款的cshtml渲染罰款,我只需要創建此文本框開始創建更多的收件人。
非常感謝你
彙編錯誤: – 2012-03-22 13:50:26
@CarlosGuillermoBolañosLopez:什麼是錯誤? – Shyju 2012-03-22 13:52:13
Compilerfehlermeldung:CS0411:方法'System.Web.Mvc.Html.LabelExtensions.LabelFor的類型參數(System.Web.Mvc.HtmlHelper ,System.Linq.Expressions.Expression >)'不能從使用情況中推斷出來。嘗試明確指定類型參數。 –
2012-03-22 13:53:36