MVC

2016-12-04 7 views
0

私たちは、私はすべてのコントローラのために公共の関数として、このコードを使用する方法を見つけるしたいと思い、このMVC

Private Function ModalValidation(Message As String) As JavaScriptResult 
    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 JavaScript(SB.ToString) 
    Catch ex As Exception 
     EmailError(ex, 77, "LoginController") 
     Return Nothing 
    End Try 
End Function 

のようなコントローラで定義されたいくつかのポップアップを持っているので、我々ドン各ページに追加する必要がありますが、モジュールで利用できないController.JavaScriptのハンドルを取得する方法がわかりません。

これをどのように達成できますか?

おかげ

============== EDIT ============= ========= SOMEビューのコードを追加しました==

<form> 
    <div id="PopupModal" Class="modal fade in out"> 
     <div class="modal-dialog"> 
      <div Class="modal-content"> 
       <div Class="modal-header"> 
        <Button Class="close" aria-hidden="true" type="button" data-dismiss="modal">×</Button> 
        <h4 Class="modal-title" id="ModalTitle"></h4> 
       </div> 
       <div Class="modal-body" id="ModalBody"> 
        <h5 id="ModalBodyText"></h5> 
       </div> 
       <div Class="modal-footer"> 
        <Button Class="btn btn-default" type="button" data-dismiss="modal">Close</Button> 
       </div> 
      </div> 
     </div> 
    </div> 

</form> 

答えて

0

使用ViewBag.Messageレイアウトページに、このjqueryのコードを追加し、JavaScriptコードに含まれています。

すべてのページがメッセージパラメータに渡すだけです。

@{ 
ViewBag.Message= "Hello World"; 
} 
+0

どうしたらいいのか分かりませんが、_Layout.vbhtmlからスニペットを追加しました – gchq