O.O
O.O

Reputation: 11317

How to post an attribute value?

I have an enum:

public enum EffectType
{
    None,
    Positve,
    Negative
}

I've three divs:

<div id="divNone"></div>
<div id="divPositive"></div>
<div id="divNegative"></div>

After the user clicks one of these three, the markup will be:

<div id="divNone"></div>
<div id="divPositive" class="selected"></div>
<div id="divNegative"></div>

How do I post the selected div and identity the selected EffectType in the controller so I can save the value to the data store?

Upvotes: 0

Views: 65

Answers (2)

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21376

You can use Jquery post ,

$.post('controler/YourAction',{effectType:$('div.selected').attr('id')},function(data){

});

And in your action,

Public ActionResult YourAction(string effectType){
   return view();
}

Upvotes: 1

Tejs
Tejs

Reputation: 41256

I would associate some data with the element that you can lookup when the click event happens:

<div id="divNone" data-effect-type="0" class="effectType selected">

$('#someButton').click(function()
{
     var effectType = $('.effectType').find('.selected').data('effect-type');

     $.ajax({
         ...
     });
});

Upvotes: 4

Related Questions