我正在尝试将我的模型传递给局部视图。当它被传入时,我想设置参数的值。当我运行它时,我得到:
Object reference not set to an instance of the object
怎么能这么说,因为我通过了这个模型?
@using passTextbox.Models
@model passTextbox.Models.MyViewModel
@Html.TextBoxFor(t=>t.someobject)
@{ Html.RenderAction("test", new MyViewModel() { someobject = "$('#somevalue')" });}
public class MyViewModel
{
public string someobject { get; set; }
}
部分视图:
@model passTextbox.Models.MyViewModel
<h2>test</h2>
<script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var tb = @Model.somevalue;
tb.val("new value");
});
</script>