value of a Model property send as a parameters to

2019-08-07 14:33发布

问题:

I'm using the Bootstrap File Input plugin and I'm trying to get the product_ID Model property value from following form and send as a parameters to controller method.

this is the form

@model project_name.Models.relavantmodel

@using (Html.BeginForm())
{
   @Html.EditorFor(model => model.Product_ID)

   <input id="idd" type="file" class="file">

   // form sumbit button
   <input type = "submit" value="Create" /> 

}

I have following controller

    [HttpPost]
    public ContentResult UploadFiles(string product_ID, string type)
    {
      .........
    }

I referred this question also

I'm trying to use following script for call upload method and send parameters


Approach 1 :

$("#idd").fileinput({
    type: 'POST',   
    uploadUrl: '/Home/UploadFiles', // server upload action
    uploadExtraData: { 'product_ID': document.getElementById('#Product_ID').value, 'type': "marketing_materials_EN" },

});

Approach 2 :

$("#idd").fileinput({
    type: 'POST',        
    uploadUrl: '@Url.Action("UploadFiles", "Home")',
    uploadExtraData: { product_ID: $('#Product_ID').val(), 'type': "marketing_materials_EN" },

Approach 3 :

 $("#idd").fileinput({
        type: 'POST',        
        uploadUrl: '@Url.Action("UploadFiles", "Home" ,new {product_ID = @Model.Product_ID , type = "marketing_materials_EN" })',

Approach 4 :

$("#idd").fileinput({

      uploadUrl: '/Home/UploadFiles',
      uploadExtraData: function () {
          return {
                  extradata: JSON.stringify({ product_ID: $('#Product_ID').val(), type: "marketing_materials_EN"})
          };

Approach 5 :

$("#idd").fileinput({

      uploadUrl: '/Home/UploadFiles',
      uploadExtraData: function () {
          return {
                  extradata: { product_ID: $('#Product_ID').val(), type: "marketing_materials_EN"}
          };

But above approach 1, 2 and 3 , I cannot get the product_ID that I'm inserting, .But I can send type

Once I put debug point at controller method I can see type value that is getting like below

and product_ID getting NULL

Approach 4 and 5 , getting null for both product_ID and type parameters

How can I get the product_ID here