0

form action dynamically changed in locally machine but can't changed/fire in hosting or IIS local server.

My cshtml code is:

@model RetailMaster.POS.Web.ViewModels.BrandTypeViewModel

@using (Ajax.BeginForm(
        "CreateBrandType", "Setup",
        new AjaxOptions { OnFailure = "InsertFail", OnSuccess = "InsertSuccess" },
        new { id = "formAdd" }
    ))
{
    @Html.ValidationSummary();

    <div class="form-group">
        @Html.HiddenFor(m => m.BTID)

        <div class="row">
            <div class="col-md-6 col-sm-6">@Html.LabelFor(m => m.BTName)</div>
            <div class="col-md-6 col-sm-6">@Html.TextBoxFor(m => m.BTName, new { @class = "form-control" })</div>
        </div>
    </div>


    <div class="form-group">
        <p>
            @*All button click event handle by jquery*@
            <input id="btnSave" type="submit" value="Save" name="save" class="btn btn-lg btn-primary" />
            <input id="btnUpdate" type="submit" value="Update" class="btn btn-lg btn-info" />
        </p>
    </div>
}

js code:

$("#btnSave").click(function () {
    var form = $("#formAdd");
    form.attr("action", "/Setup/CreateBrandType");
});


$("#btnUpdate").click(function () {
    var form = $("#formAdd");
    form.attr("action", "/Setup/UpdateBrandType");
});

C# code upder setup controller:

public ActionResult CreateBrandType(BrandTypeViewModel model){}

problem: form action can't changed dynamically. showing error in js console "SyntaxError: JSON.parse: unexpected character of the JSON data"

try these solution but fail, Change form's action attribute

Jquery to change form action

Changing the action of a form with javascript/jquery

Community
  • 1
  • 1
  • 1
    That error message doesn't seem to relate to the problem being described. What actually causes that message? What is the data which is being parsed as JSON? What does that data actually contain when the message occurs? – David Aug 24 '15 at 13:11
  • I agree with @David ...that message is not related to the issue – Hackerman Aug 24 '15 at 13:15

0 Answers0