2017-07-27 72 views
0
打開按鈕的點擊新窗口或標籤
[HttpPost] 
    public ActionResult Index(DebuggerIndexFormHolder holder) 
    { 
     var result = _debuggerIndexFormProcessor.Process(holder.DebuggerIndexForm, ModelState); 
     if (result.IsSuccess) 
     { 
      return RedirectToAction("Item", new { id = result.SessionId }); 
     } 


    } 

    [HttpGet] 
    public ActionResult Item(string id, string inputId) 
    { 
     var model = _debuggerSessionViewModelBuilder.Build(id, inputId); 
     return View(model); // it opens the required view in same window 
    } 

HTML代碼我想用MVC

<button id="submit" type="submit" data-loading-text="Loading..." class="btn btn-primary">Debug it!</button>   

的ActionResult「指數」之稱,並且輪流調用的ActionResult「項目」,通過會話ID爲動作結果「Item」,它在會話ID基礎上填充模型,然後調用View,我需要使用相同的會話ID在不同的窗口中打開此視圖。 任何人都可以幫我嗎? 謝謝

+0

當驗證失敗時,它也打開新窗口,這不是預期的行爲,任何人都可以幫助嗎?我正在使用formtarget =「_ blank」 – Dev

+0

我想要這個提交按鈕始終處於啓用狀態,我已經使用下面的 $(document).ready(function(){ \t \t \t $('#submit')。on ( 'error.field.bv',函數(例如,數據){ \t \t \t \t e.preventDefault(); \t \t \t \t如果(data.bv.getSubmitButton()){ \t \t \t \t \t數據.bv.disableSubmitButtons(false); \t \t \t \t} \t \t \t}) \t \t \t \t。對( 'success.field.bv',函數(例如,數據){ \t \t \t \t \t e.preventDefault(); \t \t \t \t \t如果(data.bv.getSubmitButton()){ \t \t \t \t \t \t data.bv.disableSubmitButtons(假); \t \t \t \t \t} \t \t \t \t}); \t \t}); – Dev

+0

使用上面的代碼,它被啓用,並再次被禁用。在cshtml頁面中沒有表單標籤。提前感謝! – Dev

回答

0

這不是你可以從服務器端代碼控制的東西。您需要爲您的button添加formtarget="_blank"屬性。

<button id="submit" type="submit" formtarget="_blank" data-loading-text="Loading..." class="btn btn-primary">Debug it!</button>  

這是否會打開一個新標籤或一個新窗口取決於用戶的瀏覽器設置。

+0

感謝它的工作,最初我嘗試使用Edge,在Edge中有一些問題用於發佈請求,但它在其他瀏覽器上工作。 – Dev

+0

當驗證失敗時,它也打開新的窗口,這不是預期的行爲,你有什麼想法? – Dev