Template source not passing correct model to a partial

0 Answers 50 Views
Templates
Rodrigo
Top achievements
Rank 1
Rodrigo asked on 07 Jun 2022, 03:06 PM

Hi!

I'm trying to render a a template that has a form in it, the form is attached to aa ActionViewModel and the source of this template is a list of this ActionViewModel from my MainViewModel. I want to add a list of nested forms as I click in "Include action" button

Here is my MainViewModel:

public class MainViewModel {
    (...)
    public List<ActionViewModel> ActionSet {get; set;} = new List<ActionViewModel>();
    (...)
}


Here is my main cshtml:

@model MainViewModel
(...)
<div class="row">
	<div class="col-md-4 form-group">
		<button class="k-button" title="Include action" data-bind="click: includeAction">
			<i class="icon-add-2"></i> Include action
		</button>
	</div>
</div>
<div data-template="template-action" data-bind="source: @(model).ActionSet"></div>
(...)

<script id="template-action" type="text/x-kendo-template">
	<div data-role="sgewexpandable" data-bind="value: this" style="margin-bottom: 10px;">
		<div data-role="sgewexpandableheader" class="text-center">
			<label data-bind="text: ActionType.Description"></label>
		</div>
		<div id="action#=uid#"
			 class="form-group">
			@Html.Partial("_IncludeAction.cshtml").ToDecoded()
		</div>
	</div>
</script>

The problem is:

My _IncludeAction.cshtml is using ActionViewModel as model, but when I try to load this page, I get an error saying it was passed MainViewModel to the partial, instead of ActionViewModel, can anybody help me?

Neli
Telerik team
commented on 10 Jun 2022, 09:05 AM

Hi Rodrigo,

The issue seems more MVC and Razor syntax related than related to the usage of the Kendo Templates. Could you please try the following syntax and let me know about the result?

<div data-template="template-action" data-bind="source: @Model.ActionSet"></div>

Regards,

Neli

No answers yet. Maybe you can help?

Tags
Templates
Asked by
Rodrigo
Top achievements
Rank 1
Share this question
or