How to pass content of the editor to controller

4 posts, 0 answers
  1. Michel
    Michel avatar
    18 posts
    Member since:
    Sep 2011

    Posted 06 Sep Link to this post

    Hi, I need help.

    I'm working with asp.net Core 1.0 RC1 and the Telerik UI for ASP.NET MVC Q2 2016 with latest .714 patch

    I would like to pass the content of an editor to my controller when clicking on a button without use of a model.

    My View

    <p>
        <a asp-action="SaveScreen" asp-route-strValue="???????" asp-route-strMessage="My Message" id="#LINE1_SCR" SaveScreen" class="btn btn-primary">Save</a>
    </p>
     
    <div>
        @(Html.Kendo().Editor()
        .Name("LINE1_SCR")
        .Tools(tools => tools.Clear().Bold().FontName().ForeColor().BackColor())
        .Tag("DivLine")
        .Value(@<text><p>Content of the editor</p></text>)
        )
    </div>

    My controller

    public async Task<IActionResult> SaveScreen(string strMessage)
        {
        var strControllerMessage = strMessage;
        return View();
        }

    As you can see I pass parameters using the "asp-route..." razor syntax feature of asp.net core.

    But I don't find any way to use the right syntax for passing the content of the editor in the "strValue" parameters of the push button.

    Any help will be very appreciated.

    Best regards.

     

  2. Ianko
    Admin
    Ianko avatar
    1535 posts

    Posted 07 Sep Link to this post

    Hello Michel,

    I am not sure that there is a tag helper syntax that will let you dynamically override the predefined routing parameter. 

    Also I noticed some other issues:

    1. The id attribute is a plain DOM attribute and the way it is used produces invalid HTML: 

      id="#LINE1_SCR" SaveScreen"

      I assume it should be 

      id="SaveScreen"

    2. The Editor's Tag method should be used with HTML tags. Like "Div".

      .Tag("Div")

    Generally, the case you are after should be implemented additionally and there is no syntax to automate that. You can, for example, handle the anchor's click event and assign additionally the query string needed for the strMessage field to be populated. Like in this example:  

    <a asp-action="SaveScreen" asp-route-strValue="value" id="SaveScreen" class="btn btn-primary">Save</a>
     
    <div>
        @(Html.Kendo().Editor()
        .Name("LINE1_SCR")
        .Tools(tools => tools.Clear().Bold().FontName().ForeColor().BackColor())
        .Tag("Div")
        .Value(@<text><p>Content of the editor</p></text>)
        )
    </div>
     
    <script>
        (function () {
            $("#SaveScreen").click(function (ev) {
                ev.target.href = ev.target.href + "&strMessage=" +
                                    encodeURIComponent($("#LINE1_SCR").data("kendoEditor").value());
            });
     
        })();
    </script>

    Regards,
    Ianko
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Michel
    Michel avatar
    18 posts
    Member since:
    Sep 2011

    Posted 07 Sep in reply to Ianko Link to this post

    Hi Ianko,

    Many thanks for the reply, Yes about the syntax mistake (just copy/paste error).

    So I understand that there is no razor syntax for it. By the way your solution with Javascript (what I would like to avoid) works well.

    Best regards.

    Ps : Could be interesting to add a background image feature to the editor

  5. Ianko
    Admin
    Ianko avatar
    1535 posts

    Posted 07 Sep Link to this post

    Hello Michel,

    If the topic about the background-image is related to a non-existing feature, you can submit this as a feature request on UserVoice.

    If, however, this is related to a specific functionality you nee, please open a new thread as this topic is not related to the one discussed here. 

    Regards,
    Ianko
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready