JsonResult asks the user to download the json file when submitting the form?

Using JsonResult causes the form submission to ask the user if they want to download the json file?

My controller is:

 [HttpGet]
        public ActionResult Edit(int id)
        {
         
            tbl_MyTable tbl = (from x in DB.MyTable
                             where x.ID == id
                             select x).Single();

            return View(edit);

        }

[HttpPost]
        public JsonResult Edit(List<newList> formData)
        {
            var result = new { Success = "", Message = "" };
            try
            {
                   foreach (var item in formData)
                {
                    tbl_MyTable  Data = (from x in DB.tbl_MyTable
                                             where x.ID == item.ID
                                             select x).Single();

                    Data.Type = item.Type;
                    Data.Name = item.Name;
                    Data.Version = item.Version;
                    Date = item.Date;
                }

                DB.SaveChanges();
                TempData["msg"] = "<script>swal('Item successfully updated!');</script>";

            }

            catch (Exception ex)
            {
                Utility util = new Utility();
                string error = util.innerExcep(ex);
                result = new { Success = "False", Message = error };
                return Json(result);
            }

            result = new { Success = "True", Message = "Success" };
            return Json(result);

        }
        }

My View is: (Shortened snippet below)

@model master.Models.tbl_MyTable
@{
    ViewBag.Title = "Edit Item";
    ViewBag.submittable = true;
    master.Models.SelectLists sl = new master.Models.SelectLists();
}
   
@using (Html.BeginForm())
{
    @Html.HiddenFor(x => x.ID)

<div class="row" style="margin-top: 0;">

                        <div class="col-xs-3">
                            @Html.Label("Type")
                            @Html.DropDownListFor(x => x.Type, sl.getTypes(), new
                       {
                           @type = "drop",
                           @style = "width: 255px;",
                       })                      
                        </div>
<div class="col-xs-8 col-xs-offset-1">
                            @Html.Label("Name")
                            @Html.TextBoxFor(x => x.Name, Model.Name, new
                       {
                           @class = "form-control",
                           @maxlength = "255",
                       })                  
                        </div>
                    </div>

<div class="col-xs-3">
                                @Html.Label("Date")
                                @Html.TextBoxFor(x => x.Date, Model.Date.ToString(), new
                           {
                               @class = "form-control",
                               @type = "date",
                               @maxlength = "15",
                           })
                            </div>

 <div class="row">
                        <div class="col-xs-12">
                            <button type="submit" class="btn btn-success" style="float: right;" onclick="javascript: submitForm();">
                                Submit Changes
                            </button>
                        </div>
                    </div>

<script type="text/javascript">
    function submitForm() {

        if ($("#Type").val() != '' && $("#Name").val() != '' && $("#Date").val() != '' ) {
            var type = $("#Type").val();
            var name = $("#Name").val();
            var date = $("#Date").val();

            var formData = [
                {
                    Type: type, Name: name,
                    Date: date,
                    ID: $("#ID").val(),
                }
            ];

            $.post('@Url.Action("Edit", "MyController")', { "formData": formData })
                .done(function (data, status) {
                    if (data.Success == "True") {
                        var link = '@Url.Action("MyList", "MyController")';
                        window.location.href = link;
                    }
                    else {
                        swal({
                            title: "Error",
                            text: data.Message,
                            type: "error"
                        }, function () {
                            var link = '@Url.Action("Edit", "MyController")';
                            window.location.href = link;
                        });
                    }
                });
        }
        else {
            swal({
                title: "Error",
                text: "Please complete required fields.",
                type: "error"
            }, function () {
                url = '@Url.Action("Edit", "MyController", new { id = Model.ID })';
                    window.location.href = url;
                });
        }
    }

</script>


@if (!string.IsNullOrEmpty(ViewBag.Error))
{
    <script type="text/javascript">
            swal({
                title: "Error",
                text: "@ViewBag.Error",
                type: "error"
            }, function () {
                url = '@Url.Action("Edit", "MyController", new { id = Model.ID })';
                window.location.href = url;
            });
    </script>
}
Crystal RouseTask LeadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Your post needs the 'JSON' parameter to tell jQuery you are expecting a JSON return

$.post(url, data, callback, 'JSON');

Open in new window


Try that.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Crystal RouseTask LeadAuthor Commented:
Thanks! That is what was missing!
Julian HansenCommented:
You are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.