Skip to main content
Updated code and added additional explanation.
Source Link
Willy David Jr
  • 9.2k
  • 7
  • 51
  • 62

I am not sure what you really want to accomplish, but based on your question, you want to get the value on the property you have on your Model with 3 Models inside:

Try this on your Javascript section:

 <script type="text/javascript"> $document.ready(function () { var itemitems = "<option value='0'>Select</option>";  var itemWithViewProperty = @Html.Raw(Json.Encode(Model.SpecificModel.DistrictID));    //Now you can use this variable 'itemWithViewProperty' and prints its value like: Console.Log(itemWithViewProperty); //But accessing it like $('#DistrictID').html(items); will not work since its an element ID you are passing here and not a variable value }); 
  

Make sure to specify the specific model after the Model word.

Try this on your Javascript section:

var item = @Html.Raw(Json.Encode(Model.SpecificModel.DistrictID)); 
 

Make sure to specify the specific model after the Model word.

I am not sure what you really want to accomplish, but based on your question, you want to get the value on the property you have on your Model with 3 Models inside:

Try this on your Javascript section:

 <script type="text/javascript"> $document.ready(function () { var items = "<option value='0'>Select</option>";  var itemWithViewProperty = @Html.Raw(Json.Encode(Model.SpecificModel.DistrictID));    //Now you can use this variable 'itemWithViewProperty' and prints its value like: Console.Log(itemWithViewProperty); //But accessing it like $('#DistrictID').html(items); will not work since its an element ID you are passing here and not a variable value }); 
 

Make sure to specify the specific model after the Model word.

Source Link
Willy David Jr
  • 9.2k
  • 7
  • 51
  • 62

Try this on your Javascript section:

var item = @Html.Raw(Json.Encode(Model.SpecificModel.DistrictID)); 

Make sure to specify the specific model after the Model word.