在视图中填充模型并传递控制器

sal*_*lar 6 c# asp.net-mvc

我在asp.net中遇到很多问题因为我是新手.所以我搜索,但我没有找到我的答案.

首先,我的视图引擎是aspx不是剃刀,这是我的主要问题.

这是视图

        <%= Html.HiddenFor(model => model.SharingPremiumHistoryID) %>
    <%= Html.HiddenFor(model => model.ItemId) %>
    <div class="group">
        <span> ????? ?? </span>
        <%= Html.DropDownListFor(model => model.SharingTargetType, Model.SharingTypes) %>
    </div>
</hgroup>
<div class="newseditor">
    <div class="input-form">
        <%= Html.LabelFor(model => model.SharingTitle, "????? ???") %>
        <%= Html.TextBoxFor(model => model.SharingTitle) %>
    </div>

    <div class="input-form">
        <%= Html.LabelFor(model => model.Content, "??? ???") %>
        <%= Html.TextAreaFor(model => model.Content) %>
    </div>
    <div><input id="fileUpload" type="file" />

    </div>
                   <button name="post" type="submit" >????? ???</button>
Run Code Online (Sandbox Code Playgroud)

因为你有一些填充模型的项目.

现在我的问题是如何通过提交按钮将此视图传递给控制器​​(带有Ajax).

这是控制器

  public virtual ActionResult Add()
    {
        var model = new ResturantSharingViewModel();

        model.SharingTargetType = getSharingTargetTypesSelectListItems();
        return PartialView(model);
    }
Run Code Online (Sandbox Code Playgroud)

Jas*_*ell 1

在您的视图中包含以下代码:

 <% using(Html.BeginForm("HandleForm", "Home")) %>
    <% { %>
       // your code for your page goes here
        <input type="submit" value="Submit" />
    <% } %>
Run Code Online (Sandbox Code Playgroud)

然后在你的控制器中有这样的代码:

  public ActionResult HandleForm()
  {
            // do controller logic here

            return View("FormResults");
  }
Run Code Online (Sandbox Code Playgroud)