i am trying to pass in my model to a partial view. When it is passed in I would like to set the value of the argument. When I run this i get:
Object reference not set to an instance of the object
How can it say that because I passed in this Model?
@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; }
}
partialview:
@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>
Try to use
Html.RenderPartialinstad ofHtml.RenderActionIn the View
and finally in the Partial view