Are you talking about in context of View? If yes then you can create strongly typed View using one of ViewModel class. Then you will have the type of that model in View. The topmost line in View.
Get model's type in controller
Question
Is there any way to get a type of model
without accessing to the parameters?
My controller:
[HttpPost]
public ActionResult SomeAction(SomeViewModel model)
{
SomeMethod(/* How to pass models's type here? */)
}
private void SomeMethod(Type type)
{
// come code
}
Method SomeMethod(Type type)
will be called in many other actions. And
Type modelType = typeof(SomeViewModel);
or
Type modelType = model.GetType();
are not suitable.
No correct solution
OTHER TIPS
I think there is a misunderstanding with a model and what the form submits to the server. In most cases the model has several infos about the page, like title, description, userprofile and so on. When you push submit on a form you send to the action only the fields included in the form. It means that most data are not available in that action and you have to create it manually
Take a look to that code:
<h1>@Model.ArticleTitle</h1>
<p>@Model.ArticleDescription</p>
<form method="post">
@Html.EditFor(x=> x.CommentTitle)
@Html.EditFor(x=> x.CommentBody)
</form>
In that case the browser sends to the server only the CommentTitle and the CommentBody. ArticleTitle and ArticleDescription are not sent.
.u