Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fill the Model in view and pass it controller

Tags:

c#

asp.net-mvc

I have many problem in asp.net because i am new with that . so i searched but i did not find my answer.

First of all my view engine is aspx is not razor and it is my mostly problem .

this is View

        <%= 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>

as you so i have some item that fill the model .

now my question is how i pass this view to controller(with out Ajax) with submit button .

and this is controller

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

        model.SharingTargetType = getSharingTargetTypesSelectListItems();
        return PartialView(model);
    }
like image 440
salar Avatar asked Feb 03 '15 20:02

salar


2 Answers

You need to use a Html.BeginForm and add HttpPost to the controller action.

like image 95
beautifulcoder Avatar answered Oct 20 '22 01:10

beautifulcoder


Have this code in your view:

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

Then have code like this in your controller:

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

            return View("FormResults");
  }
like image 45
Jason Roell Avatar answered Oct 19 '22 23:10

Jason Roell