• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1097
  • Last Modified:

MVC using webservice as Model - UIHint

I am creating an MVC project that uses the model from an external web service. I am using a telerik Grid for MVC, and want to use an EditorTemplate for one of the fields. Everything I have read so far has led me to believe that I need to decorate my Model with UIHint to enable a field for an Editor Template, but I do not have a model.

How should I achieve this? Preferably, I do not want to have to create a Model, but have I gone about this the wrong way? Should I always create a Model. Can anyone point me in the direction of some resources that will give me a good example? I am fairly new to asp.net development and also MVC.
0
leedurrant
Asked:
leedurrant
  • 2
1 Solution
 
ventaurCommented:
I would create a view model that is filled with data from the Web service in the controller action, then pass the view model to the view personally. Then, you can decorate the property on your view model with the UIHint and any other goodies you may want for validation purposes.

However, if you just want to get through this as-is, you can change your view so it is told which Editor Template to use for that field/property. If you are rendering the entire model via Html.EditorForModel, you will have to change the view to render and editor for each property instead (unless you use a view model). Then, your individual Html.EditorFor or Html.Editor calls can be modified to specify which template to use.

<%= Html.EditorFor(model => model.SomeProperty, "MyTemplate") %>

Open in new window

0
 
leedurrantAuthor Commented:
HI ventaur,

Thanks for the response. I have actually added a model anyway and it is now working. From your email, it does sound as though it is the best route to follow.
0
 
ventaurCommented:
That is good to hear. I think you'll find that sometimes you may even want to combine some data from multiple models; perhaps from multiple web services. A view model lets you combine just the data you need for the view, regardless of how disparate the data's source may be.

Good luck!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now