0

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.

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.