Fill the model in sight and pass it to the controller

I have a lot of problems in asp.net because I am new to this. so I searched, but I did not find the answer.

Firstly, my aspx viewing engine is not a razor, and this is my main 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> 

since you have an element that fills the model.

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

and this is the controller

  public virtual ActionResult Add() { var model = new ResturantSharingViewModel(); model.SharingTargetType = getSharingTargetTypesSelectListItems(); return PartialView(model); } 
+6
source share
2 answers

Enter this code in your view:

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

Then in your controller there should be such code:

  public ActionResult HandleForm() { // do controller logic here return View("FormResults"); } 
+1
source

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

+2
source

Source: https://habr.com/ru/post/981939/


All Articles