I want to pass two values from controller action to asp.net MVC 3 Razor view. I am doing like this in action method:
var model = new { reportid = rid, refno = refernumber};
return View(model );
but when i try to access it in view like this:
@Model.reportid
I get, object doesn't contain property reportid
How can I pass multiple values without using viewbag ?
Well, i strongly recommend you to use ViewModel class. But if for some reason you have phobia of extra viewmodel classes, you can use C# feature called Tuple
var model = Tuple.Create(firstObject, secondObject)
and then your view will be of type Tuple, for example
@model Tuple<int, string>
and you can access them like this
@Model.Item1
And then you can congratulate yourself, you have achieved nice mess with hidden meaning :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With