c# - How to pass parent view data when using partial view -
i have dropdownlist in parent view , when select value want save value , use when click button in partial view. if click button in partial view not have value of parent view. however, if move dropdownlist partial view works fine, keep in parent view.
parent view (this dropdownlist is)
<div class="btn-toolbar"> <div class="btn-group"> <button type="button" class="btn btn-primary" id="fetchprocessid">fetch process id</button> </div> </div> <div class="col-md-3" style="@displayadminlead"> <div class="dropdown div-inline"> @{ var envlist = new list<selectlistitem>() { new selectlistitem() {value = "oak", text = "oak"}, new selectlistitem() {value = "qa", text = "qa"}, new selectlistitem() {value = "prod", text = "prod"} }; } @html.dropdownlistfor(m => m.environmentname, envlist, "environment", new {@class = "form-control"}) </div> </div> <div style="overflow: auto"> @using (html.beginform()) { <div id="fetchprocessiddiv" style=""> @html.action("fetchprocessid", model) </div> } </div>
partial view
<table class="table table-hover"> <tbody> <tr> <td>system name:</td> <td> @html.dropdownlistfor(m => m.fetchprocessidmodel.systemname, new selectlist(model.fetchprocessidmodel.dropdownoptions, "valueid", "value")) </td> <td rowspan="2">@html.textareafor(m => m.fetchprocessidmodel.message, 12, 50, null)</td> </tr> <tr> <td>deliverable id:</td> <td>@html.textboxfor(m => m.fetchprocessidmodel.deliverableid)</td> </tr> </tbody> </table> <input type="submit" name="submit" class="btn btn-default" value="fetch process id" />
parent model
public class parentmodel { public string environmentname { get; set; } }
controller
[httppost] public actionresult parentclass(string submit, parentmodel model) { //omit var envname = model.environmentname; //i not seeing value model.environmentname @ point }
in order input post it's value controller, needs inside form element.
<div style="overflow: auto"> @using (html.beginform()) { <div class="btn-toolbar"> <div class="btn-group"> <button type="button" class="btn btn-primary" id="fetchprocessid">fetch process id</button> </div> </div> <div class="col-md-3" style="@displayadminlead"> <div class="dropdown div-inline"> @{ var envlist = new list<selectlistitem>() { new selectlistitem() {value = "oak", text = "oak"}, new selectlistitem() {value = "qa", text = "qa"}, new selectlistitem() {value = "prod", text = "prod"} }; } @html.dropdownlistfor(m => m.environmentname, envlist, "environment", new {@class = "form-control"}) </div> </div> <div id="fetchprocessiddiv" style=""> @html.action("fetchprocessid", model) </div> } </div>
Comments
Post a Comment