This is a migrated thread and some comments may be shown as answers.

RenderPartial and RenderAction in edittemplate

5 Answers 367 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chrys
Top achievements
Rank 1
Chrys asked on 08 May 2013, 04:02 PM
I have a grid with an edit template specified and withing that grid I'm trying to use either render partial or renderaction. Both i've gotten to work with the actually editing and adding that is not my problem. The problem is the data for my partial inside my edittemplate is not being populated with data. Here is my edit template.

@model <BaseFormModel>
@{
    Model.Demographics = Model.GetFormDemographics(Model.PlanActivityId, Model.Id, 0);
}
<div class="modalContent">
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true)
 
        <fieldset>
            <legend>Edit Events</legend>
            <div>
                <label>Month</label>
                @Html.TextBoxFor(model => model.StartMonth, new { @placeholder = "mm" })/@Html.TextBoxFor(model => model.StartYear, new { @placeholder = "yyyy" })
            </div>
            <div>
                <label>Event Name</label>
                @Html.TextBoxFor(m => m.FormName)
            </div>
            <div>
                <label>Number of brochures distributed(if applicable)</label>
                @Html.TextBoxFor(m => m.Count2, new { @maxlength = 3 })
            </div>
            <div>
                <label>Number of attendees</label>
                @Html.TextBoxFor(m => m.Count, new { @id = "txtNumberOfAttendees" })
            </div>
            <a id="autoPopulate">Populate based on my county census and number of attendees.</a>
            <h2>Target Demographics</h2>
            @*@{
        Html.RenderAction("GetFormDemographics", "Form", new { planActivityId = ViewBag.PlanActivityId, formId = Model.Id, spUserId = 0 });
            }*@
            @{
                Html.RenderPartial("_PartialDemographicsEditor",model: Model.Demographics);
            }
        </fieldset>
    }
</div>
How do I get my renderpartial or renderaction to work or is there some other way to use partials in kendo edittemplates for grids.

5 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 10 May 2013, 12:02 PM
Hello Chrys,

I am not sure what could be causing the problem. Could you also provide the code for the PartialView? Also, are you using Server or Ajax editing for the Grid? If you are using Ajax binding then the problem could be caused by not using the same names for the inputs as in the model. The PartialView helper does not add a prefix so the name of the inputs will be "MyProperty" instead of "Demographics.MyProperty
". In this case you could either pass the whole model to the partial view are add a prefix:

@Html.Partial("_PartialDemographicsEditor", Model.Demographics,
           
              new ViewDataDictionary() { TemplateInfo = new TemplateInfo { HtmlFieldPrefix  = "Demographics"} }
          )
If you are using server binding then the problem could be caused by the form. In server binding mode the Grid adds a form on its own and nested forms are not supported.

Kind regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chrys
Top achievements
Rank 1
answered on 13 May 2013, 03:04 PM
@model Papr2WebMvc4.Models.PiprDemographic.Demographic
@using (Html.BeginForm())
{
    @Html.HiddenFor(model => model.TotalPopulation)
    @Html.HiddenFor(model=>model.Genders)
    <div class="formColumns fiveColumn media">
 
        <div class="column1">
            <h3>Gender</h3>
            @foreach (var gender in Model.Genders)
            {
                <span>
                    <label for="'GenderCount'+">@gender.GenderDesc</label>
                    @Html.TextBox("GenderCount" + gender.GenderId, gender.Count, new { @class = "genderCounts",onchange="changed(this)" })
                </span>
            }
 
            <b>@Html.Label("Total: ", new { @id = "lblGenderTotal" })</b>
            @Html.Hidden("GenderTotal", 0)
        </div>
 
        <div class="column2">
            <h3>Ages:</h3>
            @foreach (var age in Model.Ages)
            {
                <span>
                    <label>@age.AgeDesc</label>
                    @Html.TextBox("AgeCount" + age.AgeId,age.Count,new { @class = "ageCounts",onchange="changed(this)" })
                </span>
            }
 
            <b>@Html.Label("Total: ", new { @id = "lblAgeTotal" })</b>
            @Html.Hidden("AgeTotal", 0)
        </div>
 
        <div class="column3">
            <h3>Race:</h3>
            @foreach (var race in Model.Races)
            {
                <span>
                    <label>@race.RaceDesc</label>
                    @Html.TextBox("RaceCount" + @race.RaceId,race.Count,new { @class = "raceCounts",onchange="changed(this)" })
                </span>
            }
 
            <b>@Html.Label("Total: ", new { @id = "lblRaceTotal" })</b>
            @Html.Hidden("RaceTotal", 0)
        </div>
 
        <div class="column4">
            <h3>Ethnicity:</h3>
            @foreach (var ethnicity in Model.Ethnicities)
            {
                <span>
                    <label>@ethnicity.EthnicityDesc</label>
                    @Html.TextBox("EthnicityCount" + @ethnicity.EthnicityId,ethnicity.Count,new { @class = "ethnicityCounts",onchange="changed(this)" })
                </span>
            }
 
            <b>@Html.Label("Total: ", new { @id = "lblEthnicityTotal" })</b>
            @Html.Hidden("EthnicityTotal", 0)
        </div>
 
        <div class="column5">
            <h3>Socioeconomic Status:</h3>
            @foreach (var socioEconomicStatus in Model.SocioEconomics)
            {
                <span>
                    <label>@socioEconomicStatus.SocioEconomicDesc</label>
                    @Html.TextBox("SocioEconomicStatusCount" + @socioEconomicStatus.SocioEconomicId,socioEconomicStatus.Count,new { @class = "socioCounts",onchange="changed(this)" })
                </span>
            }
 
            <b>@Html.Label("Total: ", new { @id = "lblSocioTotal" })</b>
            @Html.Hidden("SocioTotal", 0)
        </div>
 
    </div>
    <script type="text/javascript">
         
    </script>
}
Here is my partial view
I'm also using strictly ajax on this.
0
Accepted
Chrys
Top achievements
Rank 1
answered on 13 May 2013, 03:57 PM
Thanks Daniel your suggestion along with reworking my partial fiew with for loops that worked like i.e(
 for loop from i to Model.Genders.Count
{
@Html.TextBoxFor(model=>model.Genders[i].Count)
}

Made it work perfectly.
0
Chrys
Top achievements
Rank 1
answered on 20 May 2013, 05:20 PM
Don't know if I should have started a new thread for this or not.

Your suggestion works fine for reading back but what do I need to do to bind this back to model on my add and edit actions. I have a demographics object now on my edit action but its not bound to my object that I'm using as my model.
0
Petur Subev
Telerik team
answered on 22 May 2013, 02:07 PM
Hello Chrys,

We are not sure what exactly is going wrong from the code. Can you put this into a small sample project and send it so we can debug and see what exactly goes wrong?

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Chrys
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Chrys
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or