English 中文(简体)
部分使用“光电发动机”
原标题:Using a different viewmodel in partial view using Spark view engine

我使用ASP.NET MVC &Peign,认为其中有一些搜查。 2. 以上观点如下:

<viewdata model="IEnumerable<SearchModel>" />

在同一个搜索页上,我还提供了部分内容,作为供用户增加新搜索的人群窗口的内容。

我的问题是:从部分观点来看,我想利用高度打造的超文本助手来撰写:

${Html.TextBoxFor(model => model.SearchPhrase)}

但当我补充说:

<viewdata model="CreateSearchModel" />

在部分意见档案的顶端,Seta没有。 只有一种观点数据模型才能宣布。

我可以使用正常的超文本助手,但我如何能够从这种偏狭观点中获得使用强硬的超文本助手的好处——或者说这样做的方法完全更好?

最佳回答

不用加提; 用途档案=“部分”/“> 试图这样做

# Html.RenderPartial("partial", mydata);

这应当围绕单一模式限制开展工作。

问题回答

您可以提出部分意见:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CreateSearchModel>" %>

所用名称

<% Html.RenderPartial("../PartialView", (CreateSearchModel)ViewData["MyCreateSearchModel"] ); %>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!