I have a problem where my text boxes are not being populated with existing data. I have two submit buttons, but the problem appears to happen when I call; return View("Index", siteInfo);. Here is my code;

    // GET: NewEntry
    public ActionResult Index() {
        return View();
    }

    /// <summary>
    /// Generate a password. 
    /// </summary>
    /// <param name="siteInfo"></param>
    /// <returns></returns>
    [HttpPost]
    [MultipleButton(Name = "action", Argument = "GeneratePassword")]
    public ActionResult GeneratePassword(SiteInfo siteInfo) {

        //generate the password
        PasswordGenerator generator = new PasswordGenerator(NumLetters, NumNumbers, NumSymbols);
        siteInfo.Password = generator.GeneratePassorwd();

        //redirect to current view with errored object
        return View("Index", siteInfo);
    }//end method

@using PasswordManager.Models;
@using PasswordManager.Repositories;

@model PasswordManager.Models.SiteInfo

@{
    ViewBag.Title = "New Entry";
}

<h2>New Entry</h2>

@Scripts.Render("~/Scripts/jquery-ui-1.10.2.min.js")

<link href='@Url.Content("~/Content/themes/base/jquery-ui.css")' rel="stylesheet" type="text/css" />

<div class="jumbotron">
    <h1>New Entry</h1>
    <p class="lead">Add password information to the password manager. </p>
</div>

<div class="container">
    <!-- Left side. -->
    <div class="col-md-2">
        <ul id="links">
            <li><a href="@Url.Action("Index", "Home")">Home page</a></li>
        </ul>
    </div>

    @using (Html.BeginForm()) {
    <!-- Right Side. -->
            <div class="col-md-10">
                <h2>New Entry</h2>

                <!-- Site Name. -->
                <div class="form-group">
                    <label class="control-label col-md-4" for="txtSiteName">Site Name:</label>
                    <div class="col-md-8">
                        @Html.TextBoxFor(model => model.SiteName, new { @class = "form-control", id = "txtSiteName" })
                    </div>
                </div>

                <!-- Login Url. -->
                <div class="form-group">
                    <label class="control-label col-md-4" for="txtLoginUrl">Login Url:</label>
                    <div class="col-md-8">
                        @Html.TextBoxFor(model => model.LoginUrl, new { @class = "form-control", id = "txtLoginUrl" })
                    </div>
                </div>

                <!-- Password. -->
                <div class="form-group">
                    <label class="control-label col-md-4" for="txtPassword">Password:</label>
                    <div class="col-md-8">
                        @Html.TextBoxFor(model => model.Password, new { @class = "form-control", id = "txtPassword" })
                    </div>
                </div>
                <button id="btnGeneratePassword" name="action:GeneratePassword" type="submit" class="btn btn-primary" value="GeneratePassword">Generate Password</button>

                <!-- Description. -->
                <div class="form-group">
                    <label class="control-label col-md-12" for="txtDescription">Description:</label>
                    <div class="form-control-static col-md-12">
                        @Html.TextAreaFor(model => model.Description, new { @class = "form-control", id = "txtDescription" })
                    </div>
                </div>
                <button id="btnSubmit" name="action:SubmitEntry" type="submit" class="btn btn-primary" value="SubmitEntry">Submit Entry</button>
            </div>
    }
</div>

Sorry, the problem is that the code is not posting the model on reply. It is not filling the text box when I click the generate password button. The model does not post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.