Copied to clipboard

Flag this post as spam?

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


  • Mathias valling 16 posts 126 karma points
    Dec 13, 2018 @ 12:54
    Mathias valling
    0

    Passing Data to model from view

    I have a "normal" cloud setup. I used the UaaS to clone down the project, which gave me a Web and a Core project. the core project holds my models and controller. the web my view and.

    Now in the view i have some nested content which i loop like this:

    @if (Model != null){
    var items = Model.Content.Theme;
    foreach (var item in items)
    {
        int nextPage = ((PublishedContentModel)item.GetProperty("themePage").Value).Id;
    
        <h2 class="headline" data-id="@nextPage"> @nextPage</h2>
    
        using (Html.BeginUmbracoForm<conservative.Core.Controllers.UserProfileController>("SelectedTopic", null))
        {
            <input onclick="myFunction('' + @nextPage + '')" type="submit" value="@item.GetPropertyValue("themeName")">
        }
    }}
    

    only thing i need is to get the ID from the themePage and send it to my model , in the core project so i can use it in the controller. right now I'm trying to do in the myFunction

    <script>
    function myFunction(nextPage) {
    
        @conservative.Core.Models.UserProfileModel.TopicPageId = nextPage;
        document.getElementById("demo").innerHTML = nextPage;
    
    }
    

    Whenever i try to pass the data in the foreach i only get the last ID. it is overridden. So in my controller i don't know which button a user have clicked on.

    have tried to pass with:

    using (Html.BeginUmbracoForm<UserProfileController>("SelectedTopic", null, new { ThemeId = TopicId }))
    

    with no luck I'm sure i'm just missing some simple thing. Really hope someone out here knows what I'm missing

    kind regards a new cloud developer :) H5YR

  • Pawel Bres 39 posts 160 karma points c-trib
    Dec 13, 2018 @ 15:43
    Pawel Bres
    0

    Hi Mathias,

    you could try something like this:

    using (Html.BeginUmbracoForm<conservative.Core.Controllers.UserProfileController>("SelectedTopic", null))
    {
            <input type="hidden" name="ThemeId" value="@nextPage" />
            <input type="submit" value="@item.GetPropertyValue("themeName")">
    }
    

    Then you will have nextPage value posted to the controller as ThemeId

    Pawel

  • Mathias valling 16 posts 126 karma points
    Dec 14, 2018 @ 08:07
    Mathias valling
    100

    Hi Pawel

    Found a solution

    using(Html.BeginUmbracoForm<conservative.Core.Controllers.UserProfileController>("SelectedTopic", new { @TopicPageId = ThemeId }))
    {
        <input type="submit" value="@item.GetPropertyValue("themeName")">
    }
    

    Now i just need to test if I can send more then one value :)

Please Sign in or register to post replies

Write your reply to:

Draft