asp.net - How to incorporate another controller's view and behavior into "this" controller's view? -


i have jqueryui tabbed html page, , in content area 1 of tabs, have put follows:

<div id="tabs-1ua">                                @renderpage("~/views/admin/create.cshtml") </div> 

the create.cshtml page correctly appear within tab, when create user (this view basic user creation page) , click button, nothing happens. no user created , no error presented. "this" html tabs in different controller not have model associations. user creation inside admincontroller, pertinent methods shown below:

public actionresult create() {     return view(); }   [httppost] public async task<actionresult> create(createmodel model) {   if (modelstate.isvalid)   {     appuser user = new appuser { username = model.name, email = model.email};      identityresult result = await usermanager.createasync(user,                     model.password);       if (result.succeeded)         {            return redirecttoaction("index");         }      else         {             adderrorsfromresult(result);          }      }             return view(model); } 

i put breakpoint @ beginning of post method, never hit when accessed create page within other page.

when access page directly , create user, expected behavior new creation , validation. model follows:

  public class createmodel     {         [required]         public string name { get; set; }         [required]         public string email { get; set; }         [required]         public string password { get; set; }     } 

and create.cshtml view follows:

@model identitydevelopment.models.createmodel @{ viewbag.title = "create user";} <h2>create user</h2> @html.validationsummary(false) @using (html.beginform()) {     <div class="form-group">         <label>name</label>         @html.textboxfor(x => x.name, new { @class = "form-control" })     </div>     <div class="form-group">         <label>email</label>         @html.textboxfor(x => x.email, new { @class = "form-control" })     </div>     <div class="form-group">         <label>password</label>         @html.passwordfor(x => x.password, new { @class = "form-control" })     </div>     <button type="submit" class="btn btn-primary">create</button>     @html.actionlink("cancel", "index", null, new { @class = "btn btn-default" }) } 

my questions are, possible trying do? if changes need make in order reuse existing available code?

thank you.

you may explcitly specify action method form should post when submit button clicked.

you can use overload of html.beginform method so.

public static mvcform beginform(     htmlhelper htmlhelper,     string actionname,     string controllername ) 

so update create view.

@model identitydevelopment.models.createmodel @using (html.beginform("create","admin")) {    @html.textboxfor(x => x.name, new { @class = "form-control" })    <button type="submit" class="btn btn-primary">create</button> } 

now nomatter include view, post admin/create


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -