2017-03-21 9 views
0

私はmvcのバルクsmsに取り組んでいます。私はSendSMSという名前のビューを持っています。ここには、Sender ID、Numbers、Messagetextのようなフィールドがあります。ここでは、送信者ID、送信者名からなる送信者テーブルからSenderIDの値を取得しています。メッセージを送信する前に、別のビューから送信者名を追加します。現在、送信者名が追加されています。 SendSMSビューのdropdownListを使用して送信者名を表示できます。mvcのコントローラにドロップダウン値を渡すにはどうすればいいですか?

送信者IDと送信者名を作成した後、ユーザーはSendSMSビューを入力してメッセージを送信します。ユーザーはドロップダウンリストを使用して送信者名を選択します。彼は、数字とメッセージのテキストを追加します。ユーザーが送信ボタンをクリックすると、ドロップダウン値はコントローラーに渡されます。

@using (Html.BeginForm("SendMessage", "SendSMS", FormMethod.Post, new { enctype = "multipart/form-data" })) 
{        
@Html.AntiForgeryToken() 
<div class="form-horizontal"> 
    <h4>Compose New Message</h4> 
    <hr /> 
    @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 
    <div class="form-group"> 
     @Html.LabelFor(Model => Model.SendSMSModel.SenderType, new { @class = "form-control-label" }) 
     <div class="input-group"> 
      <span class="input-group-addon input_email"> 
       <i class="fa fa-user text-primary"></i> 
      </span> 
      @Html.EnumDropDownListFor(Model => Model.SendSMSModel.SenderType, new { @class = "form-control form-control-md" }) 
      @Html.ValidationMessageFor(Model => Model.SendSMSModel.SenderType, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

    <div class="form-group"> 
     @Html.LabelFor(Model => Model.SendSMSModel.SenderId, new { @class = "form-control-label" }) 
     <div class="input-group"> 
      <span class="input-group-addon input_email"> 
       <i class="fa fa-sort-numeric-asc text-primary"></i> 
      </span>         
      @Html.DropDownList("SenderId", new SelectList(ViewBag.SenderNameList, "SenderId", "SenderName"), "-Please Select-", new { @class = "form-control" }) 
      @Html.ValidationMessageFor(Model => Model.SendSMSModel.SenderId, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

    <div class="form-group"> 
     @Html.LabelFor(Model => Model.SendSMSModel.Numbers, new { @class = "form-control-label" }) 
     <div class="input-group"> 
      <span class="input-group-addon input_email"> 
       <i class="fa fa-sort-numeric-asc text-primary"></i> 
      </span> 
      @Html.TextBoxFor(Model => Model.SendSMSModel.Numbers, new { @class = "form-control form-control-md" }) 
      @Html.ValidationMessageFor(Model => Model.SendSMSModel.Numbers, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

    <div class="form-group"> 
     @Html.LabelFor(model => model.SendSMSModel.MessageText, new { @class = "form-control-label" }) 
     <div class="input-group"> 
      <span class="input-group-addon input_email"> 
       <i class="fa fa-file-text text-primary"></i> 
      </span> 
      @Html.EditorFor(model => model.SendSMSModel.MessageText, new { htmlAttributes = new { @class = "form-control", @onkeyup = "javascript:ValidateCharactercount(this);", @rows = "10", @cols = "50" } }) 
      @Html.ValidationMessageFor(model => model.SendSMSModel.MessageText, "", new { @class = "text-danger" }) 
     </div> 
     <div id="divmessage" style="color: Red;"> 
     </div> 
    </div> 


    <div class="form-group"> 
     <div class="col-md-offset-2 col-md-10"> 
      <input type="submit" value="Send Now" class="btn btn-info" /> 
     </div> 
    </div> 
</div> 

コントローラー:

`[HttpPost] 
     [ValidateAntiForgeryToken] 
     public ActionResult SendMessage(SMS_SignatureModel sms) 
     { 
      Inetlab.SMPP.SmppClient client = new Inetlab.SMPP.SmppClient(); 


      client.Connect("***.**.***.**", ****); 

      if (client.Status == ConnectionStatus.Open) 
      { 
       client.SystemType = "****"; 
       client.Bind("******", "******", ConnectionMode.Transmitter); 

       if (client.Status == ConnectionStatus.Bound) 
       { 
        IList<SubmitSmResp> respList = client.Submit(
         SMS.ForSubmit() 
         .From(sms.SendSMSModel.SenderId) 
         .To(sms.SendSMSModel.Numbers) 
         .Text(sms.SendSMSModel.MessageText) 
         .DeliveryReceipt() 
         .Coding(DataCodings.Default) 
         ); 

        if (respList.Count > 0 && respList[0].Status == CommandStatus.ESME_ROK) 
        { 
         Console.WriteLine("SMS has been sent"); 
         foreach (SubmitSmResp resp in respList) 
         { 
          Console.WriteLine("MessageId: " + resp.MessageId); 
         } 
        } 

        client.UnBind(); 
       } 

       client.Disconnect(); 
      } 
      return RedirectToAction("SendMessage", "SendSMS"); 
     } 

`

ヘルプが理解されるであろう。ここで

は、ビューコードです。

+0

ご質問はありますか?あなたのコードにはどんな問題がありますか? –

+0

@StephenMuecke問題はこの行にあります。(sms.SendSMSModel.SenderId)。 senderidの値はnullになります。ドロップダウンを使用して送信者の名前を選択しています。しかし、ここでは送信者の名前を渡すことができません。 – user7090664

+0

私がデバッグすると、Numbers、messagetextなどのように、他のすべての値がビューからコントローラに渡されます。SenderIDだけがnull値を取得しています – user7090664

答えて

0
@Html.DropDownListFor(model => model.SendSMSModel.SenderId, new SelectList(ViewBag.SenderNameList, "SenderId", "SenderName"), "-Please Select-", new { @class = "form-control" }) 
+1

このコードスニペットは問題を解決するかもしれませんが、[説明を含む](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)は本当にあなたの投稿の質を向上させるのに役立ちます。将来読者の質問に答えていることを覚えておいてください。そうした人々はあなたのコード提案の理由を知らないかもしれません。 – DimaSan

関連する問題