This is a migrated thread and some comments may be shown as answers.

How to pass content of the editor to controller

3 Answers 222 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Michel
Top achievements
Rank 1
Michel asked on 06 Sep 2016, 09:06 AM

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.

 

3 Answers, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 07 Sep 2016, 10:22 AM

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
0
Michel
Top achievements
Rank 1
answered on 07 Sep 2016, 01:40 PM

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

0
Ianko
Telerik team
answered on 07 Sep 2016, 02:15 PM

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
Tags
Editor
Asked by
Michel
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Michel
Top achievements
Rank 1
Share this question
or