0
我有一個簡單的觀點:如何使用DataContract在MVC 3.0剃刀
@model Szamam.Models.Question
@{
ViewBag.Title = "Display";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Display</h2>
<fieldset>
<legend>Question</legend>
<div class="display-label">Content</div>
<div class="display-field">
@Html.DisplayFor(model => model.Content)
</div>
<div class="display-label">CreationDate</div>
<div class="display-field">
@Html.DisplayFor(model => model.CreationDate)
</div>
<div class="display-label">nickname</div>
<div class="display-field">
@Html.DisplayFor(model => model.Creator.NickName)
</div>
</fieldset>
模型類:
using System;
namespace Szamam.Models
{
public class Question
{
private string _content;
public string Content
{
get { return _content; }
set { _content = value; }
}
public User Creator
{
get { return _creator; }
set { _creator = value; }
}
public DateTime CreationDate
{
get { return _creationDate; }
set { _creationDate = value; }
}
private User _creator;
private DateTime _creationDate;
}
}
我的控制器
namespace Szamam.Controllers
{
public class QuestionController : Controller
{
//
// GET: /Question/
public ActionResult Display()
{
return
View(new Question {Content = "someContent", Creator = new User {NickName = "someNickName"}, CreationDate = DateTime.Now});
}
}
}
現在我需要使用WCF服務和我從它得到的模型類,所以問題是:
我是否需要asp.net mvc項目中的模型類,如果我將從wcf服務中獲得它?
或者我需要一些轉換器從datacontract模型類在webservice?
我會很高興,如果你能給我一些例子
問候