Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fernanda Bernardes 27 posts 147 karma points
    May 05, 2016 @ 12:05
    Fernanda Bernardes
    0

    Partial Views with parameters

    Hi, Folks !!!

    I came back with another question ... I´m following a post published by Sebastiaan Janssen (https://umbraco.com/follow-us/blog-archive/2013/7/14/moving-from-webforms-to-mvc/) that is opening my mind how how to properly migrate my uses controls V4.

    Anyway, this post it passes to the PartialView a parameter to feed the contact form selection list .. I adapted the codes shown for V7, as some command that he includes in the post have been modified by others ..

    The original command would look like this: Html.RenderPartial ( "~ / Views / Partials / Contact.cshtml" new Site_UmbracoF.Models.ComunicarErroModel {TipoComunicado = tipoErro});

    where Site_UmbracoF is the VS project name that contains the Umbraco .. Of course the Umbraco rejected the command ...

    My structure is: - Controller: ComunicarErroController.cs - Model: ComunicarErroModel.cs - Views: ComunicarErro.cshtml (which in Umbraco is within Template) and ComunicarErroForm.cshtml

    How can I pass this parameter to the PartialViews?

    Greetings!

  • Veronica Burd 76 posts 201 karma points
    May 05, 2016 @ 13:28
    Veronica Burd
    0

    Hi,

    You could use ViewData:

    @Html.RenderPartial("~/Views/Partials/Contact.cshtml", Model.Content, new ViewDataDictionary { { "PARAMNAME", new Site_UmbracoF.Models.ComunicarErroModel {TipoComunicado = tipoErro} } })
    

    Then in the partial view

    Site_UmbracoF.Models.ComunicarErroModel obj = ViewData["PARAMNAME"];
    

    I don't think you need to have the full path to the partial file though, "Contact" may be enough.

    Ver.

  • Fernanda Bernardes 27 posts 147 karma points
    May 09, 2016 @ 13:37
    Fernanda Bernardes
    0

    Hi, Veronica!!

    Thanks for you answer, by unfortunately I didn´t understand your solution. Could you explain me?

    I follow others tutorial and occurred the same. My Umbraco´s version is 7.4.3.

    enter image description here

    enter image description here enter image description hereenter image description here

Please Sign in or register to post replies

Write your reply to:

Draft