我有这个代码:
public class AccountModel
{
[Required]
[Display(Name = "Subscription ID")]
public string SubscriptionId { get; set; }
[Required]
[Display(Name = "Storage Name")]
public string StorageName { get; set; }
[Required]
[Display(Name = "Storage Key")]
public string StorageKey { get; set; }
[Required]
[Display(Name = "Hosted Name")]
public string HostedName { get; set; }
....
}
和...
$('a.sign-in').live('click', function () {
alert("BINGO!");
var id = document.getElementById('id').value;
var name = document.getElementById('name').value;
var key = document.getElementById('key').value;
var select = document.getElementById("listahosted");
var selected = select.options[select.selectedIndex].text;
...
}
我只想在我的模型上设置一个值 -> 将“选定”值放入模型 m.HostedName 我该怎么做?
问候
用我的观点更新
我的观点
@model WebManager.Models.AccountModel
@{
ViewBag.Title = "Account";
}
<h2>Account</h2>
<p>
Please enter your Azure account details.
</p>
@Html.ValidationSummary(true, "Invalid account. Please correct the errors and try again.")
@using (Html.BeginForm())
{
<div>
<fieldset>
<legend>Account Information</legend>
<div class="editor-label">
@Html.LabelFor(m => m.SubscriptionId)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.SubscriptionId, new { id = "id"})
@Html.ValidationMessageFor(m => m.SubscriptionId)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.StorageName)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.StorageName, new { id = "name" })
@Html.ValidationMessageFor(m => m.StorageName)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.StorageKey)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.StorageKey, new { id = "key" })
@Html.ValidationMessageFor(m => m.StorageKey)
</div>
<p>
<a href="#login-box" class="login-window">
<input type="submit" value="Apply" /></a>
</p>
</fieldset>
</div>
<div id="login-box" class="login-popup">
<!--a href="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a-->
<form method="post" class="signin" action="#">
<fieldset class="textbox">
<label class="hostedservice">
<span>Hosted Service</span>
<br />
<select id='listahosted' name='listahosted'>
<option>Choose your hosted</option>
</select>
</label>
<br />
<label class="deployments">
<span>Role</span>
<br />
<select id='listadeployments' name='listadeployments'>
<option>Choose your role</option>
</select>
</label>
<br />
<a class="sign-in">
<input type="submit" value="Sign In" /></a>
</fieldset>
</form>
</div>
我没有把javascript放在这里。
情况是:我有一个由 JS 填充的组合框,我需要将选定的值放在我的模型上。
感谢所有帮助