Copied to clipboard

Flag this post as spam?

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


  • Frederik 2 posts 72 karma points
    Feb 10, 2017 @ 15:23
    Frederik
    0

    Set a model value, from the corresponding view?

    Hey, how can I set a model value using razor in a view? If I understand correctly, doing: Model.valueName = newValue would do nothing, as it is not the reference, so how do I "get" the model, like in fx. Html.TextBoxFor();?

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Feb 14, 2017 @ 07:48
    Dave Woestenborghs
    0

    Hi Frederik.

    What type is Model ? Is it a IPublishedContent instance or something custom ? With the first one you can't set the properties.

    Also changing model values in views is something I'm not fan of, but that is food for another discussion.

    Dave

  • Frederik 2 posts 72 karma points
    Feb 21, 2017 @ 12:55
    Frederik
    0

    I ended up solving my issue with some javascript. I would rather not have, but this is definitely the simplest solution.

    I understand why it's preferable to not change model values in views. I guess being a C# developer I tried to solve my issue using only C#, when javascript might have been the correct way.

    Thanks for your attention anyway :)

  • 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