Copied to clipboard

Flag this post as spam?

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


  • J 351 posts 606 karma points
    Jan 28, 2021 @ 13:36
    J
    0

    How to pass value from template to code behind?

    In webforms if i created a Public Property in code, i could assign a value through the template. As an example if i have a property called

    string DefaultName {get; set;}
    

    then on my template i could do something like

    <macro.... DefaultName="Michael"..../macro>
    

    How could i do the same for a MVC template if my code is something like

    @Html.Partial("~/Views/Partials/Test/Index.cshtml", new Web.Models.TestForm())
    

    I tried with this but it never worked

    @Html.Partial("~/Views/Partials/Test/Index.cshtml", new Web.Models.TestForm() new {DefaultName="Michael"})
    

    Thanks

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies