2016-11-23 14 views
0

Clickハンドラでは、div(detail_popup)のinnerHTMLをMvcHtmlStringで設定しようとしています。divのinnerHTMLをHtml.Action( "_ TaskDetail"、 "ProTask")で設定できません。

MvcHtmlString Bobo = @ Html.Action( "_ TaskDetail"、 "ProTask"); 注:_TaskDetailは部分的なビューです。

私は、HTMLビジュアライザーを使ってデバッグするときにボボを見ると完璧です。 次にinnerHTMLをそのように割り当てます:detail_popup.innerHTML = @Bobo; これはスクリプトエラーを生成します... SCRIPT1002:構文エラー 私はひょうたんを紛失しようとしています!どんな助けでも大歓迎です。 ボブ

これが割り当て私のスクリプトエラーを与えるMvcHtmlStringボボです:

@model PromanV3.Models.ProTask 

@{ 
Layout = null; 
} 

<!DOCTYPE html> 

<html> 
<head> 
<meta name="viewport" content="width=device-width" /> 
<title>Details</title> 
<style> 
    table, th, td { 
     border: 1px solid black; 
     border-collapse: collapse; 
     font: 12px Nautilus Pompilius; 
    } 

    th, td { 
     padding: 3px; 
     text-align: left; 
    } 

    table#t01 { 
     width: 35%; 
     background-color: #ffd800; 
    } 
</style> 
</head> 
<body> 
<div> 
     @System.DateTime.Now 

    <table id="t01"> 
     <tr> 
      <th>Name</th> 
      <th>Description</th> 
      <th>Owner</th> 
     </tr> 
     <tr> 
      <td>@Html.DisplayFor(model => model.TaskName)</td> 
      <td>@Html.DisplayFor(model => model.TaskDesc)</td> 
      <td>@Html.DisplayFor(model => model.TaskOwnerName)</td> 
     </tr> 

     <tr> 
      <th>Duration</th> 
      <th>Completion</th> 
      <th>Options</th> 
     </tr> 
     <tr> 
      <td>@Html.DisplayFor(model => model.Duration)</td> 
      <td>@Html.DisplayFor(model => model.CompPercentage)%</td> 
      <td>@Html.DisplayFor(model => model.TaskOptions)</td> 
     </tr> 
     <tr> 
      <th>Revision DT</th> 
      <th>Project ID</th> 
      <th>Task ID</th> 
     </tr> 
     <tr> 
      <td>@Html.DisplayFor(model => model.RevisionDT)</td> 
      <td>@Html.DisplayFor(model => model.ProjectId)</td> 
      <td>@Html.DisplayFor(model => model.TaskId)</td> 
     </tr> 
    </table> 


</div> 
</body> 
</html> 
:私は私の髪を引っ張ってきた

<!DOCTYPE html> 

<html> 
<head> 
<meta name="viewport" content="width=device-width" /> 
<title>Details</title> 
<style> 
    table, th, td { 
     border: 1px solid black; 
     border-collapse: collapse; 
     font: 12px Nautilus Pompilius; 
    } 

    th, td { 
     padding: 3px; 
     text-align: left; 
    } 

    table#t01 { 
     width: 35%; 
     background-color: #ffd800; 
    } 
</style> 
</head> 
<body> 
<div> 
     11/23/2016 1:08:14 PM 

    <table id="t01"> 
     <tr> 
      <th>Name</th> 
      <th>Description</th> 
      <th>Owner</th> 
     </tr> 
     <tr> 
      <td>Excavate Foundation</td> 
      <td>Trench will be 36 inches deep by 25 inches wide</td> 
      <td>Robert L. Wells</td> 
     </tr> 

     <tr> 
      <th>Duration</th> 
      <th>Completion</th> 
      <th>Options</th> 
     </tr> 
     <tr> 
      <td>12:00:00</td> 
      <td>50%</td> 
      <td>7</td> 
     </tr> 
     <tr> 
      <th>Revision DT</th> 
      <th>Project ID</th> 
      <th>Task ID</th> 
     </tr> 
     <tr> 
      <td>5/29/2016 12:00:00 PM</td> 
      <td>15</td> 
      <td>7</td> 
     </tr> 

     <tr> 
      <th>StartDateAct</th> 
      <th>StartDateSched</th> 
     </tr> 
     <tr> 
      <td>6/9/2016 1:15:00 PM</td> 
      <td>6/9/2016 1:15:00 PM</td> 
     </tr> 

     <tr> 
      <th>FinishDateAct</th> 
      <th>FinishDateSched</th> 
     </tr> 
     <tr> 
      <td>6/12/2016 1:15:00 PM</td> 
      <td>6/12/2016 1:15:00 PM</td> 
     </tr> 

     <tr> 
      <th>EstIntCost</th> 
      <th>EstExtCost</th> 
      <th>EstTotCost</th> 
     </tr> 
     <tr> 
      <td>20.00</td> 
      <td>14.00</td> 
      <td>34.00</td> 
     </tr> 
     <tr> 
      <th>ActIntCost</th> 
      <th>ActExtCost</th> 
      <th>ActTotCost</th> 
     </tr> 
     <tr> 
      <td>0.00</td> 
      <td>0.00</td> 
      <td>0.00</td> 
     </tr> 
     <tr> 
      <th>BudIntCost</th> 
      <th>BudExtCost</th> 
      <th>BudTotCost</th> 
     </tr> 
     <tr> 
      <td>20.00</td> 
      <td>14.00</td> 
      <td>34.00</td> 
     </tr> 
     <tr> 
      <th>SurIntCost</th> 
      <th>SurExtCost</th> 
      <th>SurTotCost</th> 
     </tr> 
     <tr> 
      <td>0.00</td> 
      <td>0.00</td> 
      <td>0.00</td> 
     </tr> 
    </table> 


</div> 
</body> 
</html> 

以下は私の部分図の簡略版であります

は私の部門です

<!-- Begin section that generates the detail popup for the task --> 
<div id="DetailBox" 
style="display: none; 
z-index: 1000; 
border: 2px solid blue; 
background: yellow; 
fill: white; 
color: black; 
padding-left: 8px; 
padding-right: 8px; 
padding-top: 3px; 
padding-bottom: 3px; 
position: absolute; 
font: 14px Nautilus Pompilius; 
width: 150px; 
height: 65px; 
"> 
<script> 
@{ 

ViewBag.vwbProject = 15; 
if (ViewBag.vwbTask==null) 
{ViewBag.vwbTask = 1;} 
} 
</script> 
</div> 

これは私のクリックハンドラである:

 function setMouseClickmt(xpos, ypos, width, height, message) 
    { 
     function inner() 
     { 
      var MultTxtBoxID = this.node.getAttribute("id"); // 'this' refers to the clear_rect (clear rectangle) of the SVG MultTxtBox 
      var MultTxtBoxElement = document.getElementById(MultTxtBoxID); // grab the element 
      var task_ID = MultTxtBoxElement.getAttribute("id"); 

      var detail_popup = document.getElementById('DetailBox'); 

      var task_index = getTaskPos(task_ID, arr_of_Tasks); 
      detail_popup.setAttribute('data-task',task_index); 
      detail_popup.setAttribute('data-project',15); 
      var tt = detail_popup.getAttribute('data-task'); 
      var pp = detail_popup.getAttribute('data-project'); 

      var ldt = new Date(); 
      var ldts = ldt.toLocaleString(); 
      //detail_popup.innerHtml = ldts + '</br>' + tt ; 

      @{      
       MvcHtmlString Bobo = @Html.Action("_TaskDetail", "ProTask"); 
      }; 
      detail_popup.innerHTML = @Bobo; 

     /* Make the 'DetailBox' div appear */ 
     detail_popup.style.display = 'block'; 
     detail_popup.style.top = (100) + 'px';// '400px';//works//mTop + 'px'; 
     detail_popup.style.left = (1200) + 'px';// //works//mLeft + 'px'; 
     detail_popup.style.width = 250;//width; 
     detail_popup.style.height = 500;//height; 
     } 
     return inner; 
    } 

これは、上のチョークというスクリプトの出力です:

   detail_popup.innerHTML = 

<!DOCTYPE html> 

<html> 
<head> 
<meta name="viewport" content="width=device-width" /> 
<title>Details</title> 
<style> 
    table, th, td { 
     border: 1px solid black; 
     border-collapse: collapse; 
     font: 12px Nautilus Pompilius; 
    } 

    th, td { 
     padding: 3px; 
     text-align: left; 
    } 

    table#t01 { 
     width: 35%; 
     background-color: #ffd800; 
    } 
</style> 
</head> 
<body> 
<div> 
     11/23/2016 1:21:34 PM 

    <table id="t01"> 
     <tr> 
      <th>Name</th> 
      <th>Description</th> 
      <th>Owner</th> 
     </tr> 
     <tr> 
      <td>Excavate Foundation</td> 
      <td>Trench will be 36 inches deep by 25 inches wide</td> 
      <td>Robert L. Wells</td> 
     </tr> 

     <tr> 
      <th>Duration</th> 
      <th>Completion</th> 
      <th>Options</th> 
     </tr> 
     <tr> 
      <td>12:00:00</td> 
      <td>50%</td> 
      <td>7</td> 
     </tr> 
     <tr> 
      <th>Revision DT</th> 
      <th>Project ID</th> 
      <th>Task ID</th> 
     </tr> 
     <tr> 
      <td>5/29/2016 12:00:00 PM</td> 
      <td>15</td> 
      <td>7</td> 
     </tr> 

     <tr> 
      <th>StartDateAct</th> 
      <th>StartDateSched</th> 
     </tr> 
     <tr> 
      <td>6/9/2016 1:15:00 PM</td> 
      <td>6/9/2016 1:15:00 PM</td> 
     </tr> 

     <tr> 
      <th>FinishDateAct</th> 
      <th>FinishDateSched</th> 
     </tr> 
     <tr> 
      <td>6/12/2016 1:15:00 PM</td> 
      <td>6/12/2016 1:15:00 PM</td> 
     </tr> 

     <tr> 
      <th>EstIntCost</th> 
      <th>EstExtCost</th> 
      <th>EstTotCost</th> 
     </tr> 
     <tr> 
      <td>20.00</td> 
      <td>14.00</td> 
      <td>34.00</td> 
     </tr> 
     <tr> 
      <th>ActIntCost</th> 
      <th>ActExtCost</th> 
      <th>ActTotCost</th> 
     </tr> 
     <tr> 
      <td>0.00</td> 
      <td>0.00</td> 
      <td>0.00</td> 
     </tr> 
     <tr> 
      <th>BudIntCost</th> 
      <th>BudExtCost</th> 
      <th>BudTotCost</th> 
     </tr> 
     <tr> 
      <td>20.00</td> 
      <td>14.00</td> 
      <td>34.00</td> 
     </tr> 
     <tr> 
      <th>SurIntCost</th> 
      <th>SurExtCost</th> 
      <th>SurTotCost</th> 
     </tr> 
     <tr> 
      <td>0.00</td> 
      <td>0.00</td> 
      <td>0.00</td> 
     </tr> 
    </table> 


</div> 
</body> 
</html> 
; 
+0

model-view-controllerタグはパターンに関する質問です。 ASP.NET-MVCの実装には特定のタグがあります。 –

答えて

0

値を渡し、かみそりのページから
...これを試してみてください。モデル(@Bobo)をJSファイルに追加

<script> 
    var tempValue = '@Bobo'; 
    setMouseClickmt(tempValue , yourOtherValues....); 
</script> 

あなたはかみそりページのスクリプトタグでそれを使用するときに、あなたのJSであなたのクリックハンドラ

detail_popup.innerHTML = tempValue ; 

に@Bobo周りの単一引用符を追加します。 希望すると助かります

+0

私は上記の提案を試み、この新しいスクリプトエラー "http:// localhost:58251/ProNavView/ProNavFinalView \ n \ nSCRIPT1015:行頭でJavaScriptクリティカルエラーが発生しました\ n \ nSCRIPT1015:終了しない文字列定数" –

+0

私の悪い...確かに、おそらくあなたは外部のJSファイルでそれを試した?もしそうなら、モデル(@Bobo)をクリックハンドラに渡してみてください。タグを追加して、RazorページのJSファイルに渡してください。 – user3590235

関連する問題