0

i am trying to pass files and parameters to MVC controller action. I can get my model, files in controller but cannot get my other variables in controllers such as string CommunId, string CommunContext, i know it might be because of these false parameters, but if i do not set it to false my controller action is not even invoked. Here is my code:

function submitNewCommunication(s, e) {
     // var data = new FormData($(this).serialize()); //tried this one also

        $.ajax({
            url: '@Url.Action("CreateCommunication", "Communications")',
            type: 'POST',
            data: new FormData($('.createCommunicationForm').get(0)),
            processData: false,
            contentType: false,
            success: function (result) {
                alert('test'); 
            }
        });

}

My View

@using (Html.BeginForm("CreateCommunication", "Communications", new { CommunContext = ViewBag.CommContext, CommunId = ViewBag.CommId }, FormMethod.Post, new { @class = "createCommunicationForm"}))
{
//some code
}

My MVC controller:

        public ActionResult CreateCommunication(string CommunId, string CommunContext, string[] PartyTypes, [ModelBinder(typeof(DevExpress.Web.Mvc.DevExpressEditorsBinder))]CommunicationModel item)
    {
        var files = Request.Files;
    }

So files and model are here, but not these other variables, maybe is there a simple solution how can I obtain them ? Thanks for any help and Your time.

1 Answer 1

1

You can pass the values you require through hidden fields in the form:

@using (Html.BeginForm("CreateCommunication", "Communications", FormMethod.Post, new { @class = "createCommunicationForm"}))
{
    <input type="hidden" name="CommunContext" value="@ViewBag.CommContext">
    <input type="hidden" name="CommunId" value="@ViewBag.CommId">
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.