How to pass a textbox value from view to a controller in MVC 4?

后端 未结 5 1405
我在风中等你
我在风中等你 2021-02-13 23:56

Here i am fetching the value from database and showing it in a input field


and

5条回答
  •  误落风尘
    2021-02-14 00:53

    your link is generated when the page loads therefore it will always have the original value in it. You will need to set the link via javascript

    You could also just wrap that in a form and have hidden fields for id, productid, and unitrate

    Here's a sample for ya.

    HTML

    
    

    click me

    JS

    function changeUrl(){
       var url = document.getElementById("imgUpdate").getAttribute('href');
       var inputValue = document.getElementById('ss').value;
       var currentQ = GiveMeTheQueryStringParameterValue("quantity",url);
        url = url.replace("quantity=" + currentQ, "quantity=" + inputValue);
    document.getElementById("imgUpdate").setAttribute('href',url)
    }
    
        function GiveMeTheQueryStringParameterValue(parameterName, input) {
        parameterName = parameterName.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regex = new RegExp("[\\?&]" + parameterName + "=([^&#]*)");
        var results = regex.exec(input);
        if (results == null)
            return "";
        else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    

    this could be cleaned up and expanded as you need it but the example works

提交回复
热议问题