私は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");
}
`
ヘルプが理解されるであろう。ここで
は、ビューコードです。
ご質問はありますか?あなたのコードにはどんな問題がありますか? –
@StephenMuecke問題はこの行にあります。(sms.SendSMSModel.SenderId)。 senderidの値はnullになります。ドロップダウンを使用して送信者の名前を選択しています。しかし、ここでは送信者の名前を渡すことができません。 – user7090664
私がデバッグすると、Numbers、messagetextなどのように、他のすべての値がビューからコントローラに渡されます。SenderIDだけがnull値を取得しています – user7090664