I am working on bulk sms in mvc. I have a view named SendSMS where i have fields like Sender ID, Numbers, Messagetext. Here, I am getting value of SenderID from Sender table where it consists Sender ID, Sender Name. Before sending message, user will add Sender Name from different view. As of now, I have added Sender Name. I am able to display Sender Name using dropdownList in SendSMS view.
After creating Sender ID and Sender Name, User enters SendSMS view to send Message. User will select Sender Name using dropdown list. He will add Numbers and Message text. When user clicks on Send button, the dropdown value is to passing to controller.
Here is the view code:
@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>
Controller:
`[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");
}
`
Help would be appreciated.