2

I know there have been a lot of posts about this, but I cannot get any of the suggestions like...

Return Content("<script>alert('Hello world!');</script>")

... to work

We are just about to move from MVC to core - this worked in MVC and displayed a bootstrap modal, but I gather support for this method has been dropped in core.

This is what launches the modal 'PopupModal'

 Public Function ModalValidation(Message As String) As String
    Try
        Dim SB As New StringBuilder
        SB.Append("$(document).ready(function(){")
        SB.Append("$('#PopupModal').modal();")
        SB.Append("var vBody = document.getElementById('ModalBodyText');")
        SB.Append("vBody.innerHTML = '" & Message & "';")
        SB.Append("var vTitle = document.getElementById('ModalTitle');")
        SB.Append("vTitle.innerHTML = 'Validation';")
        SB.Append("vTitle.style.color = 'orange';")
        SB.Append("});")
        Return SB.ToString
    Catch ex As Exception
        EmailError(ex, 170, "Functions")
        Return Nothing
    End Try
End Function

and on the controller

 Private Function Modal(ModalScript As String) As JavaScriptResult
        Return JavaScript(ModalScript)
    End Function

called like this

Return Modal(ModalValidation("Got here"))

It looks like I can recreate JavaScriptResult like this

Public Class JSResult
        Inherits ContentResult
        Public Sub New(ByVal script As String)
            Me.Content = script
            Me.ContentType = "application/javascript"
        End Sub
    End Class

But then what do I use in place of

Return JavaScript(ModalScript)

Thank you

1
  • isnt a best practice friend Commented Mar 9, 2017 at 0:10

2 Answers 2

0

Figured it out

 Private Function Modal(ModalScript As String) As JSResult
        Return New JSResult(ModalScript)
    End Function
Sign up to request clarification or add additional context in comments.

Comments

-1
public ActionResult Welcome(){
  return Content("You are welcomed");
}

call this function through ajax and handle response.

1 Comment

For some reason Return Content doesn't do anything (see first part of the question)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.