Create method call passing only checked radio buttons as parameters The Next CEO of Stack OverflowDoes ID have to be unique in the whole page?Create Generic method constraining T to an EnumHow do I use reflection to call a generic method?How can I know which radio button is selected via jQuery?Label fires click function twicePass Method as Parameter using C#How to uncheck a radio button?Find out if radio button is checked with JQuery?How to check a radio button with jQuery?jQuery get value of selected radio buttonHow to call asynchronous method from synchronous method in C#?

sp_blitzCache results Memory grants

How did the Bene Gesserit know how to make a Kwisatz Haderach?

Is it professional to write unrelated content in an almost-empty email?

RegionPlot of annulus gives a mesh

Limits on contract work without pre-agreed price/contract (UK)

Rotate a column

What is the result of assigning to std::vector<T>::begin()?

Unreliable Magic - Is it worth it?

Return the Closest Prime Number

If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?

What connection does MS Office have to Netscape Navigator?

How to invert MapIndexed on a ragged structure? How to construct a tree from rules?

Can you replace a racial trait cantrip when leveling up?

How to add tiny 0.5A 120V load to very remote split phase 240v 3 wire well house

Is there a difference between "Fahrstuhl" and "Aufzug"

Sending manuscript to multiple publishers

MessageLevel in QGIS3

Why does the UK parliament need a vote on the political declaration?

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Parametric curve length - calculus

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

Won the lottery - how do I keep the money?

Is HostGator storing my password in plaintext?

Bold, vivid family



Create method call passing only checked radio buttons as parameters



The Next CEO of Stack OverflowDoes ID have to be unique in the whole page?Create Generic method constraining T to an EnumHow do I use reflection to call a generic method?How can I know which radio button is selected via jQuery?Label fires click function twicePass Method as Parameter using C#How to uncheck a radio button?Find out if radio button is checked with JQuery?How to check a radio button with jQuery?jQuery get value of selected radio buttonHow to call asynchronous method from synchronous method in C#?










0















The logic is: I have several groups of radiobuttons on the view which are responsible for several rating parameters of one company. For example:



<td>
<fieldset class="rating">
<input type="radio" id="param1" name="srating" value="5"/>
<input type="radio" id="param1" name="srating" value="4"/>
<input type="radio" id="param1" name="srating" value="3"/>
<input type="radio" id="param1" name="srating" value="2"/>
<input type="radio" id="param1" name="srating" value="1"/>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="param2" name="pgrating" value="5"/>
<input type="radio" id="param2" name="pgrating" value="4"/>
<input type="radio" id="param2" name="pgrating" value="3"/>
<input type="radio" id="param2" name="pgrating" value="2"/>
<input type="radio" id="param2" name="pgrating" value="1"/>
</fieldset>
</td>


Then I want to pass checked parameters to the controller method which looks like this



public void SaveRating(int CompanyId, int param1, int param2)

// ...



So the question is: How to combine all the checked parameters into one method call? I suppose to use jquery or mvc features. Also looking for the most efficient way to do it.



UPDATE
Can it be a solution?



 @using (Html.BeginForm("SaveRating", "MyController"))

<td>
<input style="display:none" name="CompanyID" value="@Model.ID"/>
<fieldset class="rating">
<input type="radio" id="sstar5" name="param1" value="5"/><label class="full" for="sstar5"></label>
<input type="radio" id="sstar4" name="param1" value="4"/><label class="full" for="sstar4"></label>
<input type="radio" id="sstar3" name="param1" value="3"/><label class="full" for="sstar3"></label>
<input type="radio" id="sstar2" name="param1" value="2"/><label class="full" for="sstar2"></label>
<input type="radio" id="sstar1" name="param1" value="1"/><label class="full" for="sstar1"></label>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="pgstar5" name="param2" value="5"/><label class="full" for="pgstar5"></label>
<input type="radio" id="pgstar4" name="param2" value="4"/><label class="full" for="pgstar4"></label>
<input type="radio" id="pgstar3" name="param2" value="3"/><label class="full" for="pgstar3"></label>
<input type="radio" id="pgstar2" name="param2" value="2"/><label class="full" for="pgstar2"></label>
<input type="radio" id="pgstar1" name="param2" value="1"/><label class="full" for="pgstar1"></label>
</fieldset>
</td>
<input type="submit" value="Save" />










share|improve this question



















  • 1





    Does Id Have To Be Unique In The Whole Page?

    – Taplar
    Mar 21 at 17:12












  • @Taplar Yes, I missed this while was editing code on StackOverflow, in the application they are uniqe

    – Storm
    Mar 21 at 17:14











  • Aside from the repeated id, change the name attribute to param1 and param2 respectively, then just submit the form. You don't need any logic to retrieve the selected values as only those ones are sent in the request by default. The model binder will do the rest for you, assuming you also have a CompanyId field somewhere.

    – Rory McCrossan
    Mar 21 at 17:15












  • Ok, so then is your question how to find the selected radios?

    – Taplar
    Mar 21 at 17:15











  • @Taplar Yes, and pass them to the method

    – Storm
    Mar 21 at 17:16















0















The logic is: I have several groups of radiobuttons on the view which are responsible for several rating parameters of one company. For example:



<td>
<fieldset class="rating">
<input type="radio" id="param1" name="srating" value="5"/>
<input type="radio" id="param1" name="srating" value="4"/>
<input type="radio" id="param1" name="srating" value="3"/>
<input type="radio" id="param1" name="srating" value="2"/>
<input type="radio" id="param1" name="srating" value="1"/>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="param2" name="pgrating" value="5"/>
<input type="radio" id="param2" name="pgrating" value="4"/>
<input type="radio" id="param2" name="pgrating" value="3"/>
<input type="radio" id="param2" name="pgrating" value="2"/>
<input type="radio" id="param2" name="pgrating" value="1"/>
</fieldset>
</td>


Then I want to pass checked parameters to the controller method which looks like this



public void SaveRating(int CompanyId, int param1, int param2)

// ...



So the question is: How to combine all the checked parameters into one method call? I suppose to use jquery or mvc features. Also looking for the most efficient way to do it.



UPDATE
Can it be a solution?



 @using (Html.BeginForm("SaveRating", "MyController"))

<td>
<input style="display:none" name="CompanyID" value="@Model.ID"/>
<fieldset class="rating">
<input type="radio" id="sstar5" name="param1" value="5"/><label class="full" for="sstar5"></label>
<input type="radio" id="sstar4" name="param1" value="4"/><label class="full" for="sstar4"></label>
<input type="radio" id="sstar3" name="param1" value="3"/><label class="full" for="sstar3"></label>
<input type="radio" id="sstar2" name="param1" value="2"/><label class="full" for="sstar2"></label>
<input type="radio" id="sstar1" name="param1" value="1"/><label class="full" for="sstar1"></label>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="pgstar5" name="param2" value="5"/><label class="full" for="pgstar5"></label>
<input type="radio" id="pgstar4" name="param2" value="4"/><label class="full" for="pgstar4"></label>
<input type="radio" id="pgstar3" name="param2" value="3"/><label class="full" for="pgstar3"></label>
<input type="radio" id="pgstar2" name="param2" value="2"/><label class="full" for="pgstar2"></label>
<input type="radio" id="pgstar1" name="param2" value="1"/><label class="full" for="pgstar1"></label>
</fieldset>
</td>
<input type="submit" value="Save" />










share|improve this question



















  • 1





    Does Id Have To Be Unique In The Whole Page?

    – Taplar
    Mar 21 at 17:12












  • @Taplar Yes, I missed this while was editing code on StackOverflow, in the application they are uniqe

    – Storm
    Mar 21 at 17:14











  • Aside from the repeated id, change the name attribute to param1 and param2 respectively, then just submit the form. You don't need any logic to retrieve the selected values as only those ones are sent in the request by default. The model binder will do the rest for you, assuming you also have a CompanyId field somewhere.

    – Rory McCrossan
    Mar 21 at 17:15












  • Ok, so then is your question how to find the selected radios?

    – Taplar
    Mar 21 at 17:15











  • @Taplar Yes, and pass them to the method

    – Storm
    Mar 21 at 17:16













0












0








0








The logic is: I have several groups of radiobuttons on the view which are responsible for several rating parameters of one company. For example:



<td>
<fieldset class="rating">
<input type="radio" id="param1" name="srating" value="5"/>
<input type="radio" id="param1" name="srating" value="4"/>
<input type="radio" id="param1" name="srating" value="3"/>
<input type="radio" id="param1" name="srating" value="2"/>
<input type="radio" id="param1" name="srating" value="1"/>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="param2" name="pgrating" value="5"/>
<input type="radio" id="param2" name="pgrating" value="4"/>
<input type="radio" id="param2" name="pgrating" value="3"/>
<input type="radio" id="param2" name="pgrating" value="2"/>
<input type="radio" id="param2" name="pgrating" value="1"/>
</fieldset>
</td>


Then I want to pass checked parameters to the controller method which looks like this



public void SaveRating(int CompanyId, int param1, int param2)

// ...



So the question is: How to combine all the checked parameters into one method call? I suppose to use jquery or mvc features. Also looking for the most efficient way to do it.



UPDATE
Can it be a solution?



 @using (Html.BeginForm("SaveRating", "MyController"))

<td>
<input style="display:none" name="CompanyID" value="@Model.ID"/>
<fieldset class="rating">
<input type="radio" id="sstar5" name="param1" value="5"/><label class="full" for="sstar5"></label>
<input type="radio" id="sstar4" name="param1" value="4"/><label class="full" for="sstar4"></label>
<input type="radio" id="sstar3" name="param1" value="3"/><label class="full" for="sstar3"></label>
<input type="radio" id="sstar2" name="param1" value="2"/><label class="full" for="sstar2"></label>
<input type="radio" id="sstar1" name="param1" value="1"/><label class="full" for="sstar1"></label>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="pgstar5" name="param2" value="5"/><label class="full" for="pgstar5"></label>
<input type="radio" id="pgstar4" name="param2" value="4"/><label class="full" for="pgstar4"></label>
<input type="radio" id="pgstar3" name="param2" value="3"/><label class="full" for="pgstar3"></label>
<input type="radio" id="pgstar2" name="param2" value="2"/><label class="full" for="pgstar2"></label>
<input type="radio" id="pgstar1" name="param2" value="1"/><label class="full" for="pgstar1"></label>
</fieldset>
</td>
<input type="submit" value="Save" />










share|improve this question
















The logic is: I have several groups of radiobuttons on the view which are responsible for several rating parameters of one company. For example:



<td>
<fieldset class="rating">
<input type="radio" id="param1" name="srating" value="5"/>
<input type="radio" id="param1" name="srating" value="4"/>
<input type="radio" id="param1" name="srating" value="3"/>
<input type="radio" id="param1" name="srating" value="2"/>
<input type="radio" id="param1" name="srating" value="1"/>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="param2" name="pgrating" value="5"/>
<input type="radio" id="param2" name="pgrating" value="4"/>
<input type="radio" id="param2" name="pgrating" value="3"/>
<input type="radio" id="param2" name="pgrating" value="2"/>
<input type="radio" id="param2" name="pgrating" value="1"/>
</fieldset>
</td>


Then I want to pass checked parameters to the controller method which looks like this



public void SaveRating(int CompanyId, int param1, int param2)

// ...



So the question is: How to combine all the checked parameters into one method call? I suppose to use jquery or mvc features. Also looking for the most efficient way to do it.



UPDATE
Can it be a solution?



 @using (Html.BeginForm("SaveRating", "MyController"))

<td>
<input style="display:none" name="CompanyID" value="@Model.ID"/>
<fieldset class="rating">
<input type="radio" id="sstar5" name="param1" value="5"/><label class="full" for="sstar5"></label>
<input type="radio" id="sstar4" name="param1" value="4"/><label class="full" for="sstar4"></label>
<input type="radio" id="sstar3" name="param1" value="3"/><label class="full" for="sstar3"></label>
<input type="radio" id="sstar2" name="param1" value="2"/><label class="full" for="sstar2"></label>
<input type="radio" id="sstar1" name="param1" value="1"/><label class="full" for="sstar1"></label>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="pgstar5" name="param2" value="5"/><label class="full" for="pgstar5"></label>
<input type="radio" id="pgstar4" name="param2" value="4"/><label class="full" for="pgstar4"></label>
<input type="radio" id="pgstar3" name="param2" value="3"/><label class="full" for="pgstar3"></label>
<input type="radio" id="pgstar2" name="param2" value="2"/><label class="full" for="pgstar2"></label>
<input type="radio" id="pgstar1" name="param2" value="1"/><label class="full" for="pgstar1"></label>
</fieldset>
</td>
<input type="submit" value="Save" />







c# jquery asp.net asp.net-mvc-4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 17:29







Storm

















asked Mar 21 at 17:10









StormStorm

437




437







  • 1





    Does Id Have To Be Unique In The Whole Page?

    – Taplar
    Mar 21 at 17:12












  • @Taplar Yes, I missed this while was editing code on StackOverflow, in the application they are uniqe

    – Storm
    Mar 21 at 17:14











  • Aside from the repeated id, change the name attribute to param1 and param2 respectively, then just submit the form. You don't need any logic to retrieve the selected values as only those ones are sent in the request by default. The model binder will do the rest for you, assuming you also have a CompanyId field somewhere.

    – Rory McCrossan
    Mar 21 at 17:15












  • Ok, so then is your question how to find the selected radios?

    – Taplar
    Mar 21 at 17:15











  • @Taplar Yes, and pass them to the method

    – Storm
    Mar 21 at 17:16












  • 1





    Does Id Have To Be Unique In The Whole Page?

    – Taplar
    Mar 21 at 17:12












  • @Taplar Yes, I missed this while was editing code on StackOverflow, in the application they are uniqe

    – Storm
    Mar 21 at 17:14











  • Aside from the repeated id, change the name attribute to param1 and param2 respectively, then just submit the form. You don't need any logic to retrieve the selected values as only those ones are sent in the request by default. The model binder will do the rest for you, assuming you also have a CompanyId field somewhere.

    – Rory McCrossan
    Mar 21 at 17:15












  • Ok, so then is your question how to find the selected radios?

    – Taplar
    Mar 21 at 17:15











  • @Taplar Yes, and pass them to the method

    – Storm
    Mar 21 at 17:16







1




1





Does Id Have To Be Unique In The Whole Page?

– Taplar
Mar 21 at 17:12






Does Id Have To Be Unique In The Whole Page?

– Taplar
Mar 21 at 17:12














@Taplar Yes, I missed this while was editing code on StackOverflow, in the application they are uniqe

– Storm
Mar 21 at 17:14





@Taplar Yes, I missed this while was editing code on StackOverflow, in the application they are uniqe

– Storm
Mar 21 at 17:14













Aside from the repeated id, change the name attribute to param1 and param2 respectively, then just submit the form. You don't need any logic to retrieve the selected values as only those ones are sent in the request by default. The model binder will do the rest for you, assuming you also have a CompanyId field somewhere.

– Rory McCrossan
Mar 21 at 17:15






Aside from the repeated id, change the name attribute to param1 and param2 respectively, then just submit the form. You don't need any logic to retrieve the selected values as only those ones are sent in the request by default. The model binder will do the rest for you, assuming you also have a CompanyId field somewhere.

– Rory McCrossan
Mar 21 at 17:15














Ok, so then is your question how to find the selected radios?

– Taplar
Mar 21 at 17:15





Ok, so then is your question how to find the selected radios?

– Taplar
Mar 21 at 17:15













@Taplar Yes, and pass them to the method

– Storm
Mar 21 at 17:16





@Taplar Yes, and pass them to the method

– Storm
Mar 21 at 17:16












1 Answer
1






active

oldest

votes


















0














I create a sample (it worked) for your requirement with GET method.



Use AJAX get with URL /company/SaveRating?CompanyId=1&param1=3&param2=4



And use jquery method addOrUpdateQueryStringParameter() to build URL parameters



<td>
<fieldset class="rating">
<input type="radio" id="param1" name="srating" value="5"/>
<input type="radio" id="param1" name="srating" value="4"/>
<input type="radio" id="param1" name="srating" value="3"/>
<input type="radio" id="param1" name="srating" value="2"/>
<input type="radio" id="param1" name="srating" value="1"/>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="param2" name="pgrating" value="5"/>
<input type="radio" id="param2" name="pgrating" value="4"/>
<input type="radio" id="param2" name="pgrating" value="3"/>
<input type="radio" id="param2" name="pgrating" value="2"/>
<input type="radio" id="param2" name="pgrating" value="1"/>
</fieldset>
</td>

<input type="button" value="rate" onclick="rate();"/>

<script>
function addOrUpdateQueryStringParameter(uri, key, value) $)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re))
return uri.replace(re, '$1' + key + "=" + value + '$2');

else
return uri + separator + key + "=" + value;



function rate()
var url = '/Company/SaveRating';
url = addOrUpdateQueryStringParameter(url, 'CompanyId', 1);
url = addOrUpdateQueryStringParameter(url, 'param1', $('input[name="srating"]:checked').val());
url = addOrUpdateQueryStringParameter(url, 'param2', $('input[name="pgrating"]:checked').val());
$.ajax(
url: url,
type: 'GET',
success: function (html)
//todo
,
error: function (error)
// handle

);

</script>


Update:



With your update cshtml file, it worked well (i have just tested) if you set input type hidden instead of style="display:none"



<input type="hidden" name="CompanyID" value="@Model.ID"/>





share|improve this answer

























  • Your addOrUpdateQueryStringParameter() function seems completely redundant. If you've already included jQuery in the page just use $('form').serialize()

    – Rory McCrossan
    Mar 21 at 17:28











  • because he dont have form tag so i do like this

    – Hien Nguyen
    Mar 21 at 17:29











  • If you read the comments under the question you can see the OP does have a form tag. Even if that wasn't the case there's far less verbose methods of doing what you have here.

    – Rory McCrossan
    Mar 21 at 17:30












  • but the name of input is different from parameter name in action?

    – Hien Nguyen
    Mar 21 at 17:31











  • Again, read the comments. In fact, the OP has updated with their full HTML

    – Rory McCrossan
    Mar 21 at 17:31











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55285780%2fcreate-method-call-passing-only-checked-radio-buttons-as-parameters%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I create a sample (it worked) for your requirement with GET method.



Use AJAX get with URL /company/SaveRating?CompanyId=1&param1=3&param2=4



And use jquery method addOrUpdateQueryStringParameter() to build URL parameters



<td>
<fieldset class="rating">
<input type="radio" id="param1" name="srating" value="5"/>
<input type="radio" id="param1" name="srating" value="4"/>
<input type="radio" id="param1" name="srating" value="3"/>
<input type="radio" id="param1" name="srating" value="2"/>
<input type="radio" id="param1" name="srating" value="1"/>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="param2" name="pgrating" value="5"/>
<input type="radio" id="param2" name="pgrating" value="4"/>
<input type="radio" id="param2" name="pgrating" value="3"/>
<input type="radio" id="param2" name="pgrating" value="2"/>
<input type="radio" id="param2" name="pgrating" value="1"/>
</fieldset>
</td>

<input type="button" value="rate" onclick="rate();"/>

<script>
function addOrUpdateQueryStringParameter(uri, key, value) $)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re))
return uri.replace(re, '$1' + key + "=" + value + '$2');

else
return uri + separator + key + "=" + value;



function rate()
var url = '/Company/SaveRating';
url = addOrUpdateQueryStringParameter(url, 'CompanyId', 1);
url = addOrUpdateQueryStringParameter(url, 'param1', $('input[name="srating"]:checked').val());
url = addOrUpdateQueryStringParameter(url, 'param2', $('input[name="pgrating"]:checked').val());
$.ajax(
url: url,
type: 'GET',
success: function (html)
//todo
,
error: function (error)
// handle

);

</script>


Update:



With your update cshtml file, it worked well (i have just tested) if you set input type hidden instead of style="display:none"



<input type="hidden" name="CompanyID" value="@Model.ID"/>





share|improve this answer

























  • Your addOrUpdateQueryStringParameter() function seems completely redundant. If you've already included jQuery in the page just use $('form').serialize()

    – Rory McCrossan
    Mar 21 at 17:28











  • because he dont have form tag so i do like this

    – Hien Nguyen
    Mar 21 at 17:29











  • If you read the comments under the question you can see the OP does have a form tag. Even if that wasn't the case there's far less verbose methods of doing what you have here.

    – Rory McCrossan
    Mar 21 at 17:30












  • but the name of input is different from parameter name in action?

    – Hien Nguyen
    Mar 21 at 17:31











  • Again, read the comments. In fact, the OP has updated with their full HTML

    – Rory McCrossan
    Mar 21 at 17:31















0














I create a sample (it worked) for your requirement with GET method.



Use AJAX get with URL /company/SaveRating?CompanyId=1&param1=3&param2=4



And use jquery method addOrUpdateQueryStringParameter() to build URL parameters



<td>
<fieldset class="rating">
<input type="radio" id="param1" name="srating" value="5"/>
<input type="radio" id="param1" name="srating" value="4"/>
<input type="radio" id="param1" name="srating" value="3"/>
<input type="radio" id="param1" name="srating" value="2"/>
<input type="radio" id="param1" name="srating" value="1"/>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="param2" name="pgrating" value="5"/>
<input type="radio" id="param2" name="pgrating" value="4"/>
<input type="radio" id="param2" name="pgrating" value="3"/>
<input type="radio" id="param2" name="pgrating" value="2"/>
<input type="radio" id="param2" name="pgrating" value="1"/>
</fieldset>
</td>

<input type="button" value="rate" onclick="rate();"/>

<script>
function addOrUpdateQueryStringParameter(uri, key, value) $)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re))
return uri.replace(re, '$1' + key + "=" + value + '$2');

else
return uri + separator + key + "=" + value;



function rate()
var url = '/Company/SaveRating';
url = addOrUpdateQueryStringParameter(url, 'CompanyId', 1);
url = addOrUpdateQueryStringParameter(url, 'param1', $('input[name="srating"]:checked').val());
url = addOrUpdateQueryStringParameter(url, 'param2', $('input[name="pgrating"]:checked').val());
$.ajax(
url: url,
type: 'GET',
success: function (html)
//todo
,
error: function (error)
// handle

);

</script>


Update:



With your update cshtml file, it worked well (i have just tested) if you set input type hidden instead of style="display:none"



<input type="hidden" name="CompanyID" value="@Model.ID"/>





share|improve this answer

























  • Your addOrUpdateQueryStringParameter() function seems completely redundant. If you've already included jQuery in the page just use $('form').serialize()

    – Rory McCrossan
    Mar 21 at 17:28











  • because he dont have form tag so i do like this

    – Hien Nguyen
    Mar 21 at 17:29











  • If you read the comments under the question you can see the OP does have a form tag. Even if that wasn't the case there's far less verbose methods of doing what you have here.

    – Rory McCrossan
    Mar 21 at 17:30












  • but the name of input is different from parameter name in action?

    – Hien Nguyen
    Mar 21 at 17:31











  • Again, read the comments. In fact, the OP has updated with their full HTML

    – Rory McCrossan
    Mar 21 at 17:31













0












0








0







I create a sample (it worked) for your requirement with GET method.



Use AJAX get with URL /company/SaveRating?CompanyId=1&param1=3&param2=4



And use jquery method addOrUpdateQueryStringParameter() to build URL parameters



<td>
<fieldset class="rating">
<input type="radio" id="param1" name="srating" value="5"/>
<input type="radio" id="param1" name="srating" value="4"/>
<input type="radio" id="param1" name="srating" value="3"/>
<input type="radio" id="param1" name="srating" value="2"/>
<input type="radio" id="param1" name="srating" value="1"/>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="param2" name="pgrating" value="5"/>
<input type="radio" id="param2" name="pgrating" value="4"/>
<input type="radio" id="param2" name="pgrating" value="3"/>
<input type="radio" id="param2" name="pgrating" value="2"/>
<input type="radio" id="param2" name="pgrating" value="1"/>
</fieldset>
</td>

<input type="button" value="rate" onclick="rate();"/>

<script>
function addOrUpdateQueryStringParameter(uri, key, value) $)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re))
return uri.replace(re, '$1' + key + "=" + value + '$2');

else
return uri + separator + key + "=" + value;



function rate()
var url = '/Company/SaveRating';
url = addOrUpdateQueryStringParameter(url, 'CompanyId', 1);
url = addOrUpdateQueryStringParameter(url, 'param1', $('input[name="srating"]:checked').val());
url = addOrUpdateQueryStringParameter(url, 'param2', $('input[name="pgrating"]:checked').val());
$.ajax(
url: url,
type: 'GET',
success: function (html)
//todo
,
error: function (error)
// handle

);

</script>


Update:



With your update cshtml file, it worked well (i have just tested) if you set input type hidden instead of style="display:none"



<input type="hidden" name="CompanyID" value="@Model.ID"/>





share|improve this answer















I create a sample (it worked) for your requirement with GET method.



Use AJAX get with URL /company/SaveRating?CompanyId=1&param1=3&param2=4



And use jquery method addOrUpdateQueryStringParameter() to build URL parameters



<td>
<fieldset class="rating">
<input type="radio" id="param1" name="srating" value="5"/>
<input type="radio" id="param1" name="srating" value="4"/>
<input type="radio" id="param1" name="srating" value="3"/>
<input type="radio" id="param1" name="srating" value="2"/>
<input type="radio" id="param1" name="srating" value="1"/>
</fieldset>
</td>
<td>
<fieldset class="rating">
<input type="radio" id="param2" name="pgrating" value="5"/>
<input type="radio" id="param2" name="pgrating" value="4"/>
<input type="radio" id="param2" name="pgrating" value="3"/>
<input type="radio" id="param2" name="pgrating" value="2"/>
<input type="radio" id="param2" name="pgrating" value="1"/>
</fieldset>
</td>

<input type="button" value="rate" onclick="rate();"/>

<script>
function addOrUpdateQueryStringParameter(uri, key, value) $)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re))
return uri.replace(re, '$1' + key + "=" + value + '$2');

else
return uri + separator + key + "=" + value;



function rate()
var url = '/Company/SaveRating';
url = addOrUpdateQueryStringParameter(url, 'CompanyId', 1);
url = addOrUpdateQueryStringParameter(url, 'param1', $('input[name="srating"]:checked').val());
url = addOrUpdateQueryStringParameter(url, 'param2', $('input[name="pgrating"]:checked').val());
$.ajax(
url: url,
type: 'GET',
success: function (html)
//todo
,
error: function (error)
// handle

);

</script>


Update:



With your update cshtml file, it worked well (i have just tested) if you set input type hidden instead of style="display:none"



<input type="hidden" name="CompanyID" value="@Model.ID"/>






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 21 at 17:37

























answered Mar 21 at 17:26









Hien NguyenHien Nguyen

1,4831715




1,4831715












  • Your addOrUpdateQueryStringParameter() function seems completely redundant. If you've already included jQuery in the page just use $('form').serialize()

    – Rory McCrossan
    Mar 21 at 17:28











  • because he dont have form tag so i do like this

    – Hien Nguyen
    Mar 21 at 17:29











  • If you read the comments under the question you can see the OP does have a form tag. Even if that wasn't the case there's far less verbose methods of doing what you have here.

    – Rory McCrossan
    Mar 21 at 17:30












  • but the name of input is different from parameter name in action?

    – Hien Nguyen
    Mar 21 at 17:31











  • Again, read the comments. In fact, the OP has updated with their full HTML

    – Rory McCrossan
    Mar 21 at 17:31

















  • Your addOrUpdateQueryStringParameter() function seems completely redundant. If you've already included jQuery in the page just use $('form').serialize()

    – Rory McCrossan
    Mar 21 at 17:28











  • because he dont have form tag so i do like this

    – Hien Nguyen
    Mar 21 at 17:29











  • If you read the comments under the question you can see the OP does have a form tag. Even if that wasn't the case there's far less verbose methods of doing what you have here.

    – Rory McCrossan
    Mar 21 at 17:30












  • but the name of input is different from parameter name in action?

    – Hien Nguyen
    Mar 21 at 17:31











  • Again, read the comments. In fact, the OP has updated with their full HTML

    – Rory McCrossan
    Mar 21 at 17:31
















Your addOrUpdateQueryStringParameter() function seems completely redundant. If you've already included jQuery in the page just use $('form').serialize()

– Rory McCrossan
Mar 21 at 17:28





Your addOrUpdateQueryStringParameter() function seems completely redundant. If you've already included jQuery in the page just use $('form').serialize()

– Rory McCrossan
Mar 21 at 17:28













because he dont have form tag so i do like this

– Hien Nguyen
Mar 21 at 17:29





because he dont have form tag so i do like this

– Hien Nguyen
Mar 21 at 17:29













If you read the comments under the question you can see the OP does have a form tag. Even if that wasn't the case there's far less verbose methods of doing what you have here.

– Rory McCrossan
Mar 21 at 17:30






If you read the comments under the question you can see the OP does have a form tag. Even if that wasn't the case there's far less verbose methods of doing what you have here.

– Rory McCrossan
Mar 21 at 17:30














but the name of input is different from parameter name in action?

– Hien Nguyen
Mar 21 at 17:31





but the name of input is different from parameter name in action?

– Hien Nguyen
Mar 21 at 17:31













Again, read the comments. In fact, the OP has updated with their full HTML

– Rory McCrossan
Mar 21 at 17:31





Again, read the comments. In fact, the OP has updated with their full HTML

– Rory McCrossan
Mar 21 at 17:31



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55285780%2fcreate-method-call-passing-only-checked-radio-buttons-as-parameters%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현