You must Sign In to post a response.
  • Category: ASP.Net MVC

    How to have modaldialogpopup in MVC controller C#

    [HttpPost]
    public ActionResult Add(FormCollection fileupload)
    {
    if(condition)
    {

    }
    else
    {
    ViewBag.Message = "Please select correct format";
    /// Require Message box here
    }

    return View();
    }

    I need message box in else part.
    I tried Json. Its not working perfectly.
    Suggest me some samples
  • #768079
    Hi,

    The ModalDialog Popup can be implemented in many ways in MVC.
    The Best Industry standards default and most used will be CRUD Operation in MVC application.

    But for your requirement, I guess you need just a link button ADD which add the details.
    So once the design done for the View part something like this,

    <table class="class-1">
    -------Header columns------
    @foreach (var item in Model)
    {
    ----------- Row values for respective Header--------------
    <td>
    @Html.ActionLink("Add", "Add", new { id=item.Id }) // Here the Link to Add
    </td>
    }

    </table>



    Once the above view is done. We can move the function in JavaScript where can raise the else part also there itself.

    The JavaScript logic will be like,


    $(function () {
    $(".LinkID").click(function (){

    If( Condn)
    //Call the controller function and Save the values
    Else
    alert("Please select correct format");


    Let us know if it solves your problem.

    Thanks,
    Mani

  • #768081
    You have written he condition in Jquery. It 'll be good if I have in Controller.


    Note
    * Add is not link.
    *In the condition im checking the extension of uploaded file. (So doing in Controller ActionResult method).
    If has incorrect extension, should throw error. This error Im trying to capture in the else part.

  • #768085
    Hi Lily.

    If you want that to be achieved using javascript, you can show alert message to use by using below code.

    [HttpPost]
    public ActionResult Add(FormCollection fileupload)
    {
    if(condition)
    {
    Response.Write("<script type = 'text/javascript'>alert('Uploaded sucessfully...');</script>");
    }
    else
    {
    ViewBag.Message = "Please select correct format";
    Response.Write("<script type = 'text/javascript'>alert('Please upload valid file');</script>");
    }

    return View();
    }

    Sridhar Thota.
    Editor: DNS Forum.

  • #768097
    Hai Lily,
    If you want to create a popup in MVC, you can use partial view which will be your view to be poped up.
    Below is the example:
    1. Controller

    public class CommunicationController : Controller
    {
    [ActionName("CloseWithNoAction")]
    public ActionResult CloseWithNoAction(int? id)
    {
    var model = new CloseViewModel();
    model.ComplaintID = id;

    return PartialView("_CloseWithNoAction", model);
    }
    }

    2. Partial View:

    @model CloseViewModel

    <div id="communication-close" class="modal fade in" role="dialog" aria-hidden="false" data-backdrop="static">
    <div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header">
    <div class="pull-left">
    <div class="modal-title uppercase">@StringResources.Close_Communication_And_Complaint_No_Action</div>
    </div>
    <div class="pull-right">
    <a href="#" data-dismiss="modal" data-tooltip="tooltip" data-placement="top" title="@StringResources.Close">
    <i class="fa fa-remove"></i></a>
    </div>
    </div>

    <div class="row modal-body">
    @using (Ajax.BeginForm("CloseWithNoAction", "Communication",
    new { area = "Communication", id = "#Id" },
    new AjaxOptions() { HttpMethod = "POST" },
    new { @id = "frmCloseWithNoAction" }))
    {
    <div id="statusBar"></div>

    @Html.HiddenFor(m => m.ComplaintID)

    <div class="col-sm-10 justification">
    @Html.EditorFor(m => m.Justification, "String",
    new { TextArea = true, TextAreaRow = "4", Required = true, ReadOnly = false,
    Label = StringResources.Justification, id = "txtJustification",
    Placeholder = StringResources.Please_Provide_A_Justification })
    </div>
    }
    </div>

    <div class="modal-footer">
    <div class="pull-right">
    <button type="submit" class="btn btn-primary" data-container="body"
    data-tooltip="tooltip" data-placement="top" title="@StringResources.Close_With_No_Action"
    onclick="$('#frmCloseWithNoAction').submit();">
    <i class="fa fa-remove" aria-hidden="true"></i>
    @StringResources.Close_With_No_Action
    </button>
    <button type="button" id="btnClose" class="btn btn-default"
    data-container="body" data-dismiss="modal" data-tooltip="tooltip"
    data-placement="top" title="@StringResources.Close">@StringResources.Close</button>
    </div>
    </div>
    </div>
    </div>
    </div>

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com


Sign In to post your comments