0

It would like to iterate through list and render partial view for each element:

<for each="Element elem in elements">
  <render partial="partialViewName">     
</for>

How should I pass elem to partial view? <render partial> doesn't have additional parameters. I can use html.RenderPartial, but I would like to use Spark syntax. Is it possible? It looks as if it needed to use the same ViewData and couldn't define its own model.

EDIT:

Partial view:

${elem.ID} 

OK. I can use 'elem' in partial view, but partial view doesn't know what type 'elem' is. Of course everything will work, because generated view class compiles, but I have no Intellisense in partial view.

2 Answers 2

1

<viewdata paramname="paramtype"/>

Also I never used render, I use <use name="partialname" param1="value" param2="value" .../> - maybe it's the same as render, I don't know. But defining your parameters in viewdata as shown above should also work.

Also note the <default /> element, not for this exactly question, but can also be useful since sometimes you'd want some partial parameters to be optional.

Sign up to request clarification or add additional context in comments.

1 Comment

This is the same as render. I prefer render, because its name is more appealing to me. I don't know why I didn't use <viewdata paramname="paramtype"/>, it seems obvious. Thank you.
1

Well, I don't use Spark View Engine. But it appears <render partial> does have additional parameters. See here.

So I'm guessing you need to expose a property in your partial view and set its value via with *="" assignments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.