I´m newbie in MVC3. I have a button [Generate Password] on my 'Edit' view. I need to execute a function GeneratePsw() defined in 'Admin' controller which returns a string before displaying a modal that will contain the value returned by GeneratePsw().
I also tried to put the value in a ViewBag.pwd instead return it and read it from the Modal. No success
In other words:
The user do click in [Generate Password] button. Then GeneratePsw() is called and returns a string. A Bootstrap modal should appear automatically displaying that value in a label.
In My View.....
<a href="#1" role="button" class="btn btn-primary btn-small" data-toggle="modal" onclick="location.href='@Url.Action("GeneratePsw", "Admin")';return false;"><i class="icon-lock icon-white"></i> Generate Password</a>
</div>
<div id="1" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Password generated</h3>
</div>
<div class="modal-body">
<p><strong>Password: @(ViewBag.pwd)</strong></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">OK</button>
</div>
</div>
</td>
My GeneratePsw() function:
[HttpPost]
public ActionResult GeneratePsw()
{
HomeBridgeEntities ddbb = new HomeBridgeEntities();
SqlConnection Cn = new SqlConnection(((System.Data.EntityClient.EntityConnection)ddbb.Connection).StoreConnection.ConnectionString);
SupPassGenerator sup = new SupPassGenerator(Cn);
string psw = sup.CreateRandomPassword(9);
ViewBag.psw = psw;
return RedirectToAction("Edit");
}