Reputation: 3997
Is car better than motorcycle? It all depends on the scenario you are using it. Without knowing the scenario it is not possible to make that determination!
Is Dynamic typing better than static typing for certain problems/situations.
In this case
I need to show the view when OnException() method of BaseController is called. This is one time thing and i show the error page once instead of yellow screen of death.
Suppose i need to show ErrorMessage and Stacktrace on the view. As this is one time thing is it not better to use dynamic than create a error model for this.
dynamic obj = new ExpandoObject();
obj.ErrorMessage = "message";
obj.StackTrace = "bla bla bal";
return to view.
What is the best practice. Thanks for the reply.
Upvotes: 1
Views: 1050
Reputation: 24754
"Is Dynamic typing better than static typing for certain problems/situations."
Of course.
"Suppose i need to show ErrorMessage and Stacktrace on the view. As this is one time thing is it not better to use dynamic than create a error model for this."
In this case you usually have a view model that can carry the errors with it. Sometimes I use a base view model class with:
public class ViewModelBase
{
public string ErrorMessage { get; set; }
}
Most often I'll put the errors in TempData:
TempData["Errors"] = "";
Upvotes: 1