Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a different viewmodel in partial view using Spark view engine

Using ASP.NET MVC & Spark, I have a view that is listing a number of searches. The view has the following declaration at the top:

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

On the same search page, I also render a partial which is used as the content of a popup window that enables users to add new searches.

My problem is: in the partial view I want to make use of strongly typed HTML helpers and write:

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

But when I add another:

<viewdata model="CreateSearchModel" />

at the top of the partial view file, Spark fails with Only one viewdata model can be declared.

I can use normal HTML helpers, but how might I get the benefit of using strongly typed HTML helpers in this partial view - or is there a completely better way of doing this?

like image 799
Martin Avatar asked Feb 27 '23 19:02

Martin


1 Answers

Instead of <use file="partial"/> try to do

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

This should workaround the single Model limitation.

like image 57
queen3 Avatar answered May 01 '23 08:05

queen3