ASP.NET MVC PartialView postback: how to check data?

I use ASP.NET partial views, as in this example

<% using (Html.BeginForm()) { %>
    <table cellspacing="2" cellpadding="0" border="0" width="100%">
    <tr>
        <td><%= Html.LabelFor(model => model.PersonName)%></td>
        <td>
            <%= Html.TextBoxFor(model => model.PersonName)%>
            <%= Html.ValidationMessageFor(model => model.PersonName, "*")%>
        </td>
    </tr>
    ...
    <tr><td colspan="2"><%= Html.ValidationSummary(false) %></td></tr>
    </table>
<% } %>

I show these partial views in a jquery dialog, naming them with jquery code

$.ajax({
    type: "get",
    dataType: "html",
    url: urlAction,
    data: {},
    success: function(response) {
        $("#panelDetail").html('').html(response).dialog('open');
    }
});

and everything works and makes me happy. I can also submit the form using jquery ajax and this makes me even happier. :)

What is really annoying is that I did not understand where the validation occurs, because when this happens, it completely refreshes the page and closes the dialog.

I'm sure someone can help with this. In any case .... who will be? :)

Thanks in advance!

EDIT

This is a controller action signature with some code in it.

[HttpPost]
public ActionResult MyAction(FormCollection form) {
    string foroID = form["ForoId"];
    string foro = form["Foro"];
    string authorityId = form["AuthorityId"];
    string sezione = form["Sezione"];
    ...
}

Should I re-create the model class to validate it?

+3
2

: , JavaScript, .

-,: , , , , PartialView , () , , . , .

?. - , , , .

, 400 . Ajax success, error .

( ).

,

, , , . , FormCollection. MVC , , .

, , , . ViewPage<MyCustomType>, HttpPost , , .

. , . , , . , . , , , , , .

, , , .

+3

, , , ajax, , , , dialog('close') . .

+1

Source: https://habr.com/ru/post/1763691/


All Articles