我的ViewModel中有一些字段,我只需要在View中輸出。但是在提交表單時他們總是被髮送。這不僅令人討厭,而且也是危險的,因爲我絕對不希望這些視圖模型字段的數據綁定。OneWay Databinding for ViewModel
對於我的一些viewmodel屬性定義OneWay Databinding是否有任何改變?
THX提前
編輯:
問題IST,這些照片和ValidSizes列表被髮送回服務器,當我點擊一個ActionLink的。
public class PicturesViewModel
{
public const int SMALL = 100;
public const int MIDDLE = 150;
public const int BIG = 250;
public int PageSize { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="PicturesViewModel"/> class.
/// </summary>
public PicturesViewModel()
{
Pictures = new List<string>();
Size = SMALL;
Index = 1;
PageSize = 30;
}
/// <summary> Gets or sets the index. </summary>
public int Index { get; set; }
/// <summary>
/// Gets or sets the picture links.
/// </summary>
/// <value>The picture links.</value>
public List<string> Pictures { get; private set; }
/// <summary>
/// Gets or sets the size.
/// </summary>
/// <value>The size.</value>
public int Size { get; set; }
private List<SelectListItem> validSizes = null;
/// <summary>
/// Gets the valid sizes.
/// </summary>
/// <value>The valid sizes.</value>
public IEnumerable<SelectListItem> ValidSizes
{
get {
if (validSizes != null)
return validSizes;
validSizes = new List<SelectListItem>
{
new SelectListItem(){Text = "Small", Value = SMALL.ToString()},
new SelectListItem(){Text = "Middle", Value = MIDDLE.ToString()},
new SelectListItem(){Text = "Big", Value = BIG.ToString()}
};
return validSizes;
}
}
}
EDIT2:
<div id="pager_left">
<%= Html.ActionLink("Prev", "Prev", Model)%>
</div></td>
這就是操作鏈接引起的結合。
請提供您的查看代碼。數據綁定僅適用於請求參數。請求參數使用視圖中的表單字段創建。 – Christian13467 2010-09-08 08:00:49