0

I have a Partial view which takes in parameters and displays a Markdown Editor based on the parameters passed.

@Html.Partial("_MarkdownEditor", new { id = "fieldsection" })
<div id="@ViewData.Eval("id")"> </div>

<script type="text/javascript">
var @ViewData.Eval("id") = new tui.Editor({
el: document.querySelector('#@ViewData.Eval("id")')})
</script>

In the source code of the tui.Editor i have a Ajax call to a controller something like this..

$.ajax({
          url: 'Home/Index',
          success: function (data) {
                  editor.importManager.eventManager.emit('command', 'AddImage'})

Here the problem is with this line..

editor.importManager.eventManager.emit('command', 'AddImage)

Here in the place of editor i need to reference the parameters passed to Partial view..it should be like this:

fieldcomments.importManager.eventManager.emit('command', 'AddImage)

It should be done dynamically i have tried something like..

{@ViewData.Eval("id")}.importManager.eventManager.emit('command', 'AddImage)

But this doesn't work like this? How can i reference the Parameters passed to Partial view in a separate javascript file??

  • Please more clarify you problem what you want to do. – TAHA SULTAN TEMURI Jun 01 '18 at 05:05
  • @TAHASULTANTEMURI `{@ViewData.Eval("id")}` contains the parameters passed to Partial view. I want to use those parameters here to `{@ViewData.Eval("id")}.importManager.eventManager.emit('command', 'AddImage)` But i am not able do that.! Is there a way to use the parameter passed to Partial view in Javascript file.? – Karthik Selvam Jun 01 '18 at 07:56

1 Answers1

0

You can make the variable global in the view where you can still access @ViewData.Eval("id"). Like this answer

Example:

<script> var a = @ViewData.Eval("id") </script>

Frank Navarrete
  • 121
  • 2
  • 11
  • This doesn't solve the problem. I have no problem in my view. I wanted something like this.. `<%=@ViewData.Eval("id")%>.importManager.eventManager.emit('command', 'AddImage)` . So when i pass parameters to Partial view for ex:`@Html.Partial("_MarkdownEditor", new { id = "fieldsection" })` it set `fieldcomments.importManager.eventManager.emit('command', 'AddImage)` Is there a way to achieve this? – Karthik Selvam Jun 01 '18 at 08:33