开发者

Best practices for binding MVC model to WCF service through "datamodule"?

I'm somewhat of a noob, so bear with me please.

I'm building an MVC project that gets data from a web service (WCF) as exposed by a "datamodule" class that passes parameters to the service. Right now what I have is a viewmodel that looks like this:

public String FirstName { get; set; }
public String LastName { get; set; }
public String DisplayName { get; set; }
public String Role { get; set; } 

A "datamodule" class that looks like this:

private readonly ServiceClient _serviceClient = new ServiceClient();
public List<Info> GetStuff(int Id)
    {
        return _serviceClient.GetStuff(Id);
    }

And a controller action that looks like this:

var dm = new DataModule();
var members = dm.GetStuff(96);
    var team = from member in members
                            开发者_运维知识库select new TeamModel
                                {
                                    FirstName = member.FirstName,
                                    LastName = member.LastName,
                                    Role = member.Role,
                                    DisplayName = member.DisplayName
                                };
return PartialView(team.ToList());

I don't feel like it's very clean (or MVC like) to manually bind data like this in every one of my controllers. Is there a best practices way to bind data like this?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜