Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So I have a panel with 3 DDL, 2 TextBoxes, a Cancel button and an Apply button. I want my button work this way: When I click it, I want it to take the data from 3 DDL and 2 TextBoxes and build a model, send it to my controller/function and refresh the gridview .

But the function also has to check there is no duplicate entries.

So if that function returns a partial view, in case the entry I am adding is duplicated, how can I show a message to display the error?

button:

<button id="btnAddUpdateConfig" name="btnAddUpdateConfig" value="Apply" onclick="ValidateValues()">Apply</button>

My problem also comes before that; how can I send the values to the controller function? Is there a way to call a controller method passing values from the button? But that method will have to refresh the gridview if the item is added or show and error if it is not.

If I want to do it from JS, how can I do the same? I just know Ajax.ActionLink and that creates a link when I just want to call a controller method.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

how can I send the values to the controller function? Is there a way to call a controller method passing values from the button? Use jquery ajax call:

   function ValidateValues(){
    [email protected]("ControllerName","Action",new {param1=value,param2=value=param3=value})
    $.ajax({
    url:actionUrl,
    statusCode: {
    404: function() {
       alert("Data is duplicated");
    }
    }
    });
}

Now you can handle request in your action and if data is duplicate send the following code:

 return new HttpStatusCodeResult(404, "Data is duplicated");
share|improve this answer
    
Awesome, I also want to check if the textboxes types are correct, because I want in some of them integers and in other just strings. How and where should I check that? Action? JS? –  AnnArbor87 Jun 10 '13 at 13:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.