how to get to object in a model?
i have a model SiteMapModel that have a object VirtualFolderModel inside him.
public class SiteMapModel
{
public SiteMapModel(DataRow data)
{
SMF_ID = Convert.ToInt32(data["SMF_ID"]);
SMF_VF_ID = Convert.ToInt32(data["SMF_VF_ID"]);
VirtualFolder = new VirtualFolderModel(data);
}
public VirtualFolderModel VirtualFolder;
public int SMF_ID { get; set; }
public int SMF_VF_ID { get; set; }
}
public class VirtualFolderModel
{
public VirtualFolderModel(DataRow data)
{
VF_ID = Convert.ToInt32(data["VF_ID"]);
}
public int VF_ID { get; set; }
}
in my controller i pass the model to a view.
public ActionResult Edit(int id)
{
SiteMapData smd = new SiteMapData();
SiteMapModel smm = new SiteMapModel(smd.GetFolderData((int)id, 15));
return View(smm);
}
how to use it in my view?
&l开发者_如何学Pythont;div>
<span class="editor-label">
@Html.Label("Title")
</span>
@Html.TextBox("SMF_Name")
@Html.ValidationMessage("SMF_Name")
<span class="editor-label">
@Html.Label("VF_ID")
</span>
@Html.TextBox("VF_ID")
@Html.ValidationMessage("VF_ID")
<input type="submit" value="Save" />
</div>
the @Html.TextBox("VF_ID")
don't work
At the top of your view add this:
@ModelType SitemapModel
Edit: For C# please use:
@model SitemapModel
Doing that will simply tell your view what kind of model is given at runtime. In this case, it's an object of type SitemapModel.
In your view you can reference to it to model.SMF_ID
精彩评论