Reputation: 11
I just want to check the data from Models in View module (I.e.CSHTML
) and my trying is like this
@model CCG.Models.RatingConverter
<table>
<tbody>
<tr>
@if (Model.ToString()!="A")
{
<td class="row" ><%- Rating %></td>
}
</tr>
</tbody>
</table>
I get Null Reference Exception
error.. So please any one know..
Upvotes: 0
Views: 36416
Reputation: 1
Try this solution -
@model VievModel.MyView
Return View("MyView", ratingConverter);
Upvotes: 0
Reputation: 356
If you are getting a string from controller then
write controller method like
public ViewResult MyMethod(){
ViewBag.MyString="A";
return View();
}
in view
<table>
<tbody>
<tr>
@if (ViewBag.MyString.ToString()!="A")
{
<td class="row" ><%- Rating %></td>
}
</tr>
</tbody>
</table>
Upvotes: 0
Reputation: 197
First you pass your viewmodel from controller like this
public ActionResult ActionName()
{
//your code
return View(listautomation);
}
then bind it in your view part like this
@model ViewModel.ListAutomation
Get the value in view like this
<input type="text" id="id" value="@Model.ListAutomation " readonly="True"/>
Upvotes: 5
Reputation: 9425
You need to pass a viewmodel from your controller to your view.
For instance something like this:
var ratingConverter = new CCG.Models.RatingConverter();
//instanciate with data
Return View("MyView", ratingConverter);
Upvotes: 1