got "System.Web.Mvc.Html.MvcForm" on page - asp.net

The browser is displaying "System.Web.Mvc.Html.MvcForm" next to my form. How can I hide it?
Here is the form code.
#Html.BeginForm("NewComment", "Difficultes", FormMethod.Post)
{
#Html.HiddenFor(m => m.diff.id_diff)
<table>
<tr><label><b>Nouveau commentaire</b></label></tr>
<tr>
<td><b>Nom :</b></td><td>#Html.TextBoxFor(m=>m.pseudo)</td>
</tr>
<tr>
<td><b>Commentaire :</b></td><td>#Html.TextAreaFor(m=>m.nouveau)</td>
</tr>
</table>
<input type="submit" value="Ajouter" />
}

Change your code to (Add the #using):
#using (Html.BeginForm("NewComment", "Difficultes", FormMethod.Post))
{
#Html.HiddenFor(m => m.diff.id_diff)
<table>
<tr><label><b>Nouveau commentaire</b></label></tr>
<tr>
<td><b>Nom :</b></td><td>#Html.TextBoxFor(m=>m.pseudo)</td>
</tr>
<tr>
<td><b>Commentaire :</b></td><td>#Html.TextAreaFor(m=>m.nouveau)</td>
</tr>
</table>
<input type="submit" value="Ajouter" />
}

Change the line #Html.BeginForm("NewComment", "Difficultes", FormMethod.Post)
to #using(Html.BeginForm("NewComment", "Difficultes", FormMethod.Post))

Related

ASP.NET MVC - I can't figure out why my POST action is not being hit

I haven't worked in ASP.NET MVC for a few years so I'm a little rusty. I can't figure out what I'm missing so that my POST Action isn't being hit when I submit my form. Here's my view:
<form id="unsubscribe-form" method="post" action="Communication/Unsubscribe">
<div class="col-sm-12 col-md-9 mtl">
<button type="submit" id="btnSubmit" class="no-underline btn btn-orange btn-block">Yes, I'm Sure</button>
</div>
</form>
Here's my action:
[Route("Communication/Unsubscribe")]
[AnyAccessType]
[HttpPost]
public ActionResult Unsubscribe(UnsubscribeViewModel model)
Is there something obvious I'm missing as to why this Action wouldn't be hit?
Take a look at this question Here and this post Here
Should look something like this. If in doubt try hitting your controller with postman and see what happens. Hope this helps
#model Form_Post_MVC.Models.PersonModel
#{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width"/>
<title>Index</title>
</head>
<body>
#using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<table cellpadding="0" cellspacing="0">
<tr>
<th colspan="2" align="center">Person Details</th>
</tr>
<tr>
<td>PersonId: </td>
<td>
#Html.TextBoxFor(m => m.PersonId)
</td>
</tr>
<tr>
<td>Name: </td>
<td>
#Html.TextBoxFor(m => m.Name)
</td>
</tr>
<tr>
<td>Gender: </td>
<td>
#Html.DropDownListFor(m => m.Gender, new List<SelectListItem>
{ new SelectListItem{Text="Male", Value="M"},
new SelectListItem{Text="Female", Value="F"}}, "Please select")
</td>
</tr>
<tr>
<td>City: </td>
<td>
#Html.TextBoxFor(m => m.City)
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit"/></td>
</tr>
</table>
}
</body>
</html>
fix your action route
[Route("~/Communication/Unsubscribe")]
public ActionResult Unsubscribe(UnsubscribeViewModel model)
and form
#model UnsubscribeViewModel
.....
#using (Html.BeginForm("Unsubscribe", "Communication", FormMethod.Post))
{
....
}

ASP.NET MVC 5 form doesn't send table rows details(with jQuery datatables 1.10.15)

I created view with form that included table with rows that initialize from list, the table designed with jQuery.datatables 1.10.15.
When I tried to send the form then the table not send, I get null in the list parameter in the action controller.
View page:
#model List<SendMails.ViewModels.ViewModelDetailsFile>
#{
ViewBag.Title = "UpdateItems";
}
#using (Html.BeginForm("UpdateItems", "Home", FormMethod.Post)) {
#Html.AntiForgeryToken()
<table id="DetailsExcelChoose">
<thead>
<tr>
<th class="RightToLeft wideIndexCol">IndexRow</th>
<th class="RightToLeft">InvoiceNumber</th>
<th class="RightToLeft wideIndexCol">NumberClient</th>
<th class="RightToLeft ">NameClient</th>
<th class="RightToLeft wideIndexCol">Amount</th>
<th class="RightToLeft wideIndexCol">Email</th>
<th class="RightToLeft wideIndexCol">ContactPerson</th>
<th class="RightToLeft ">Details</th>
</tr>
</thead>
<tbody name="iObjsUpdate">
#if (Model != null)
{
for (var i = 0; i < Model.Count(); i++)
{
<tr>
<td name="IndexRow">#Model[i].IndexRow</td>
<td name="InvoiceNumber">#Model[i].InvoiceNumber</td>
<td name="NumberClient">#Model[i].NumberClient</td>
<td name="NameClient">#Model[i].NameClient</td>
<td name="Amount">#Model[i].Amount</td>
<td name="Email"><input type="email" id="Email" name="Email" value=#Model[i].Email /></td>
<td name="ContactPerson"><input type="text" id="ContactPerson" name="ContactPerson" value=#Model[i].ContactPerson></td>
<td name="Details">#Model[i].Details</td>
</tr>
}
}
</tbody>
</table>
<div class="form-group row">
<button type="submit" class="btn btn-primary">send</button>
</div>
}
JS file:
$(document).ready(function () {
var dataTable = $("#DetailsExcelChoose").DataTable();
});
Controller action:
[HttpPost]
[ValidateAntiForgeryToken]
[Route("UpdateItems")]
public async Task<ActionResult> UpdateItems(List<ViewModelDetailsFile> iObjsUpdate)
{
/// iObjsUpdate is null
}
I read that need to set the name attribute for the asp.net know what the columns are...
But all my searching in google not success.
If I didn't clear what I want so... I want to send the rows details to controller action as list of object (yes I know that I can do this in ajax but I want in this way)
For send or post row details to controller you have to use hidden fields on .cshtml or view page.
try this
for (var i = 0; i < Model.Count(); i++)
{
<tr>
#Html.HiddenFor(x => x.Model[i].IndexRow)
#Html.HiddenFor(x => x.Model[i].InvoiceNumber)
#Html.HiddenFor(x => x.Model[i].NumberClient)
#Html.HiddenFor(x => x.Model[i].NameClient)
#Html.HiddenFor(x => x.Model[i].Amount)
#Html.HiddenFor(x => x.Model[i].Email )
#Html.HiddenFor(x => x.Model[i].ContactPerson)
#Html.HiddenFor(x => x.Model[i].Details)
<td name="IndexRow">#Model[i].IndexRow</td>
<td name="InvoiceNumber">#Model[i].InvoiceNumber</td>
<td name="NumberClient">#Model[i].NumberClient</td>
<td name="NameClient">#Model[i].NameClient</td>
<td name="Amount">#Model[i].Amount</td>
<td name="Email"><input type="email" id="Email" name="Email" value=#Model[i].Email /></td>
<td name="ContactPerson"><input type="text" id="ContactPerson" name="ContactPerson" value=#Model[i].ContactPerson></td>
<td name="Details">#Model[i].Details</td>
</tr>
}

Bind images in razor view to <img src> that are in loop

Right now the only thing i want to know is how to bind the Image to the "img src" in razor view.I have searched the other questions but did not find the answer for images in loop.The current way written down does not work."~/Images/" is the folder where the uploaded images are.
#model List<propertyMgmt.Models.Property>
<div id="propertyList">
<label>Select properties to be Featured:</label><br />
<table class="table">
<tr>
<th>
#Html.Label("Property Description")
</th>
<th>
#Html.Label("Property Cost")
</th>
<th>
#Html.Label("Property Image")
</th>
<th>
#Html.Label("Featured??")
</th>
</tr>
#for (int i=0;i<Model.Count;i++)
{
<tr>
<td>
#Html.DisplayFor(m => m[i].PropertyDescription)
</td>
<td>
#Html.DisplayFor(m => m[i].PropertyCost)
</td>
<td>
<img src="~/Images/#(m=>m[i].PropertyImage)" />
</td>
<td>
#Html.CheckBoxFor(m => m[i].IsFeatured, new {
#onclick = "propertyCheckBoxSelect(this)" })
</td>
</tr>
}
</table>
</div>
You can use like this.
<img src="~/Images/#(Model[i].PropertyImage)" />

Html rendering order for asp mvc

How come my form loads like this?
Here is my code :
#using MvcApplication6.Models;
#model List<Employee>
#{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
Create Entry
</p>
<p>#Html.ActionLink("Check departments", "Index", "Department")</p>
<p>Check summary</p>
<table border="1">
<tr>
<th>
#Html.DisplayNameFor(model => model[0].id)
</th>
<th>
#Html.LabelFor(model => model[0].firstname)
</th>
<th>
#Html.LabelFor(model => model[0].lastname)
</th>
<th>
#Html.DisplayNameFor(model => model[0].gender)
</th>
<th>
#Html.DisplayNameFor(model => model[0].department)
</th>
<th>Action</th>
</tr>
#using (Html.BeginForm())
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
foreach (Employee mod in Model)
{
<tr>
<td>
<input type="hidden" value="#mod.id" name="id" id="id" />
#Html.DisplayFor(modelItem => mod.id)
</td>
<td>
#Html.DisplayFor(modelItem => mod.firstname)
</td>
<td>
#Html.DisplayFor(modelItem => mod.lastname)
</td>
<td>
#Html.DisplayFor(modelItem => mod.gender)
</td>
<td>
#Html.DisplayFor(modelItem => mod.department)
</td>
<td>
<button onclick="location.href='#Url.Action("Edit", new { id = mod.id })';return false;">Edit</button>
#Html.CheckBoxFor(modelItem => mod.selected)
</td>
</tr>
}
<br />
<input type="submit" value="submit" />
}
</table>
Here are my concerns:
Notice that i put my submit button after the foreach loop but how come it was rendered first before the actual boxes?
I've been trying to put it on the bottom but i am having some problems.
What's the ordering for render?

How to have a struts2 form in a table?

I am trying to have my form in a table but it generates a table and makes it a mess.
the generated table is as following:
<div>
<s:form action="myaction" >
<table border="1">
<tr>
<td><s:textfield name="name" label="Name" /></td>
<td><s:textfield name="family" label="Family" /></td>
<td><s:submit/></td>
</tr>
</table>
</s:form>
</div>
Source code :
<div>
<form id="myaction" name="myaction" action="/application/myaction.action" method="post">
<table class="wwFormTable"> <<<generated table
<table border="1">
<tr>
<td><tr>
<td class="tdLabel"><label for="Search_Name" class="label">Name:</label></td>
<td
><input type="text" name="Name" value="" id="Search_Name"/></td>
</tr>
</td>
<td><tr>
<td class="tdLabel"><label for="Search_Family" class="label">Family:</label></td>
<td
><input type="text" name="Family" value="" id="Search_Family"/></td>
</tr>
</td>
<td><tr>
<td colspan="2"><div align="right"><input type="submit" id="Search_0" value="Submit"/>
</div></td>
</tr>
</td>
</tr>
</table>
</table></form>
Use the "simple" theme if you do not want to use S2's default "xhtml" theme.
You'll lose S2's automatic error reporting. You may wish to consider creating your own theme.
Alternatively, you can use the "simple" theme on individual controls.
See the "Themes and templates" docs to get started.
Try to use any theme in struts form tag
eg:
<s:form action="Courses" theme="css_xhtml">
<table border="0">
<tr>
<td><s:textfield name="courseAbbr" /></td>
</tr>
</table>
</s:form>
May Be you should use this code instead...
<sp:form >
<tr>
<td>
<table>
<sp:textfield name="name"></sp:textfield>
</table>
</td>
<td>
<table>
<sp:textfield name="family"></sp:textfield>
</table>
</td>
<td>
<table>
<sp:submit/>
</table>
</td>
</tr>
</sp:form>

Resources