c# - Why is my Modal form posting a null model back to the controller -
i have partial view load in modal..in index view model div html.partial looks this.
<div class="modal fade" id="modaleditdbinfo" role="application" aria-labelledby="modaleditdbinfolabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modaleditdbinfocontent" style="background-color:white; border-radius:10px; box-shadow:10px;"> @html.partial("_editdatabaseinfo") </div> </div> </div>
the partial view code is
@model hybridinator.domain.entities.database <br /> <br /> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">close</span></button> <h4 class="modal-title" id="editmodeltitle">edit database info</h4> </div> <div class="modal-body"> @using (html.beginform("editdatabaseinfo", "database", formmethod.post, new { @class = "modal-body" })) { <div class="form-group"> <div id="databaselabel" >@html.labelfor(m => m.database, "database")</div> <div id="databaseedit" >@html.editorfor(m => m.database)</div> </div> <div class="form-group"> <div id="databaseserverlabel" >@html.labelfor(m => m.database_server, "database server")</div> <div id="databaseserveredit" >@html.editorfor(m => m.database_server)</div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">cancel</button> <button class="btn btn-inverse btn-primary" type="submit">save</button> </div> } </div>
if fire controller successfully
[httppost] public actionresult editdatabaseinfo(database database) { string s = database.database; //do other stuff homecoming redirecttoaction("index"); }
everything works fine until seek access model in controller post should passed actionresult method. model object null
object reference not set instance of object
.
anyone see im missing here?
you have pass model in header view , controller , in partialview lisk below
please in bold text , text in between ** **
**@model hybridinator.domain.entities.database** <div class="modal fade" id="modaleditdbinfo" role="application" aria-labelledby="modaleditdbinfolabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modaleditdbinfocontent" style="background-color:white; border-radius:10px; box-shadow:10px;"> @html.partial("_editdatabaseinfo", **model** ) </div> </div> [httppost] public actionresult editdatabaseinfo(database database) { string s = database.database; //do other stuff // **you have model value in here , pass index action** homecoming redirecttoaction(**"index", modelvalue**); } public actionresult index(**modelclass classvalue**) { //pass model value index view. homecoming view(**"index", classvalue**); }
c# jquery asp.net asp.net-mvc twitter-bootstrap
No comments:
Post a Comment