2014-01-09 1 views
1
@model Portal.Models.MessageModel 

<link href="~/Content/jquery.wysiwyg.css" rel="stylesheet" /> 
<script type="text/javascript" src="~/Scripts/jquery-2.0.3.js"></script> 
<script src="~/Scripts/jquery-migrate-1.2.1.js"></script> 
<script src="~/scripts/jquery.unobtrusive-ajax.js"></script> 
<script type="text/javascript" src="~/Scripts/jquery.wysiwyg.js"></script> 
<script type="text/javascript" src="~/Scripts/wysiwyg-controls/wysiwyg.image.js"></script> 
<script type="text/javascript" src="~/Scripts/wysiwyg-controls/wysiwyg.link.js"></script> 
<script type="text/javascript" src="~/Scripts/wysiwyg-controls/wysiwyg.table.js"></script> 
<script type="text/javascript" src="~/Scripts/wysiwyg-controls/wysiwyg.cssWrap.js"></script> 
<script type="text/javascript" src="~/Scripts/wysiwyg-controls/wysiwyg.colorpicker.js"></script> 

<script type="text/javascript"> 
    (function($) { 
     $(document).ready(function() { 
      $('#messagearea').wysiwyg({ 
       initialContent: function() { 
        var inittext = ""; 
        @{if (Model != null) 
         { 
          <text>inittext = '@Model.MessageText';</text> 
         } 
        } 
         return inittext; 
       } 
      }); 
     }); 
    })(jQuery); 
</script> 
    <table id="compose-table" style="border-spacing:0 0; max-width: 1200px; min-width: 450px;box-shadow: 0 0 5px 2px #cfcfcf; width:auto; background-color:white"> 
     <tbody> 
      <tr > 
       <td style="box-shadow: inset 0 0 10px #383838;"> 
        <form> 
         <div id="destinations" style="border-bottom: 1px solid #cfcfcf; padding: 12px 1px 12px 2px; ">        

          **<input name="to" spellcheck="false" autocomplete="false" autocapitalize="false" autocorrect="off" style="padding-left: 8px; background-color:transparent; width:1078px; resize:none; border: none;" placeholder="To" onfocus="displayCCandBCC" value="@Model.From"/>** 
         </div> 
         <div id="addressdiv" style="display: none"> 
          <table> 
           <tbody> 
            <tr id="cc" style="display: none"></tr> 
            <tr id="bcc" style="display: none"></tr> 
           </tbody> 
          </table> 
         </div> 

         <div id="subjectdiv" style="border-bottom: 1px solid #cfcfcf; padding : 12px 1px 12px 2px; "> 
         @{if (Model == null){ 
          <input name="subject" style="padding-left: 8px; width: 1078px; border: none; background-color: inherit" placeholder="Subject" /> 
          } 
          else 
          { 
          <input name="subject" style="padding-left: 8px; width: 1078px; border: none; background-color: inherit" placeholder="Subject" value="@String.Concat("re: ", Model.Subject)" /> 
          } 
} 
         </div> 
         <textarea id="messagearea" style="min-height:300px; width:100%; padding:0 0 0 0"></textarea> 
        </form> 
       </td> 
      </tr> 
     </tbody> 
</table> 

이 스크립트는 뷰 모델에 파고 cshtml 면도기보기에 null의 경우,하지만 난 null 참조 예외를 얻을 :

예외 정보를 : System.NullReferenceException : 개체 참조가 개체의 인스턴스로 설정되지 않았습니다.

Source Error: 

Line 20:  { 
Line 21:   Response.Write("inittext = '@Model.MessageText';"); 
Line 22:  } 
Line 23:  return inittext; 
Line 24: } 

소스 파일 : D : 메시지 \ Compose.cshtml 라인 \ 환자 포털 \ Portal.MVC \ 조회수 \ \ 프로젝트 : 22

는 이유는 무엇 Response.Write를 여전히 존재 if 조건이 false인데도 불구하고 예외가 22 행을 가리키고 21 행을 가리 키지 않는 이유는 무엇입니까? 당신이 JS 코드 블록에 있기 때문에

+0

오류는 일반적으로 뒤의 행 또는 범위를 벗어난 코드를 가리키는 행을 가리 킵니다. – gunr2171

+0

"모델"전에 "@"을 제거하지 않아도됩니까? – David

+0

@ 데이비드 내가, 그것은 버튼을 – BlackICE

답변

1

내가 이것을 테스트하는 MVC5이없는,하지만 난 당신의 Response 개체, 당신이 대신 같은 동적 자바 스크립트를 작성해야한다 null의 생각 : 또한

@if (Model != null) 
{ 
    <text>inittext = '@Model.MessageText';</text> 
} 

을 확인하십시오 Model.MessageText 때문에 제대로 이스케이프 그 내용은 자바 스크립트 오류를 ​​일으키지 않습니다.

+0

가있을 수 있습니다 나는 처음에 그했다 및 응답에 변경 I 때문에 아마도 이상한 일이 ... 태그로 진행되고 있다고 생각했습니다. – BlackICE

+1

그럴 경우 오류가 다른 곳에서 발생합니다. cshtml 파일의 상단에 정확한'@ model' 선언이 있습니까? – David

+0

예, 전 게시물에 전체 코드를 넣었습니다. – BlackICE

0

, 당신은 당신의 경우 수행 할 명시 적 CSHTML 개방 태그를 사용해야합니다.

+0

나는 그것을'@ {...} '로 감싸려고 노력했지만 도움이되지 않았다. – BlackICE

+0

당신은 ... 면도기 인터프리터가 혼동됩니다 때문에 ... 나는 이런 식으로 뭔가를 할 필요 기억 당신의 JS 스크립트 블록의 시작 부분에 변수로 저장하는 –