我使用C#和SQL Server 2005如何在ASP MVC 3
我也使用實體框架和代碼的方法首先開發一個ASP.NET的MVC 3應用程序中使用從型動物模型參數應用在同樣的觀點。
我有一個從模型視圖'FlowModelView'繼承的部分視圖,因爲我使用了這個模型中的列表。
我想使用另一個模型'Gamme'的參數。
當我嘗試這個,,,聲明總是在紅色下劃線。
這是局部視圖:
<%@ Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MvcApplication2.Models.FlowViewModel.Gamme>" %>
<% using (Html.BeginForm()) { %>
<%: Html.ValidationSummary(true) %>
<fieldset class="parametrage">
<legend>Gestion de Gamme</legend>
<div><%:Html.Label("Poste :")%><%: Html.DropDownList("SelectedPoste", Model.PostesItems)%></div>
<div><%:Html.Label("Nombre de Passage :")%><%: Html.EditorFor(Model.Gamme=>Model.Gamme.Nbr_Passage) %></div>
</fieldset>
<% } %>
這個FlowViewModel:
public class FlowViewModel
{
[Key]
public string IDv { get; set; }
[NotMapped]
public SelectList PostesItems { get; set; }
//public List<Poste> PostesItems { get; set; }
public List<Profile_Ga> Profile_GaItems { get; set; }
public List<Gamme> GaItems { get; set; }
public int SelectedProfile_Ga { get; set; }
public int SelectedGamme{ get; set; }
public int SelectedPoste { get; set; }
}
,這是的Gamme型號:
namespace MvcApplication2.Models
{
public class Gamme
{
[Key]
[Column(Order = 0)]
[ForeignKey("Profile_Ga")]
public string ID_Gamme { get; set; }
[Key]
[Column(Order = 1)]
[ForeignKey("Poste")]
public string ID_Poste { get; set; }
public int Position { get; set; }
public int Nbr_Passage { get; set; }
public string Last_Posts { get; set; }
public string Next_Posts { get; set; }
public virtual Poste Poste { get; set; }
public virtual Profile_Ga Profile_Ga { get; set; }
}
and this the controller but contains some errors :
public class AnouarController : Controller
{
//
// GET: /Anouar/
public ActionResult Gestion()
{
var model = new FlowViewModel()
{ YourGammeModel = new Gamme(){
public string ID_Gamme { get; set; }
public string ID_Poste { get; set; }
public int Position { get; set; }
public int Nbr_Passage { get; set; }
public string Last_Posts { get; set; }
public string Next_Posts { get; set; }
public virtual Poste Poste { get; set; }
public virtual Profile_Ga Profile_Ga { get; set; }
}};
return PartialView();
}
}
感謝MIXTE ,,,但是當我改變「的RenderPartial」 ,,,昨天的空例外返回 – anouar 2013-05-14 13:33:17
OK我已經回到到該聊天室 – 2013-05-14 13:36:26