-1

I have below non strongly typed html view

@{
    ViewBag.Title = "CreateNonStronglyBlog";
}

<h2>Create Non Strongly Blog</h2>

@using (@Html.BeginForm("CreateBlog","blog")){
    @Html.Label("namelable", "Put your name here", new { @id = "name" })
    @Html.TextBox("txtname", "", new { @id = "txtName"})
    @Html.Label("urllable", "Put your Url here", new { @id = "url" })
    @Html.TextBox("txturl", "", new { @id = "txturl"})
    <input type="submit" value="Create" class="btn btn-default" />
}

And below i have my controller actions to be call on submitting this form.

public ActionResult CreateBlog(Blog blg)
{
    topBlogs.Add(blg);
    return View("IndexNotStronglyTyped", topBlogs);
}

How to submit the form and send the values to controller's action method ?

Bh00shan
  • 330
  • 4
  • 16
  • 1
    You need to show your model for `Blog` (does it really contain properties name `string txtname` and `txturl`?) –  Feb 23 '17 at 06:47
  • 1
    Also your form is missing a submit button –  Feb 23 '17 at 06:49
  • Yes that is correct.. i forgot to add that :) – Bh00shan Feb 23 '17 at 06:51
  • The ModelBinding works based on input `name` attributes, which means that your `Blog` needs to have properties named `namelable`, `txtname`, `urllable` etc. What is the definition of Blog class? – Catalin Feb 23 '17 at 07:09
  • I got below answer for my question. http://stackoverflow.com/questions/16323360/submitting-html-form-using-jquery-ajax – Bh00shan Feb 23 '17 at 07:28

4 Answers4

0

declare begin form and model like this

@model yourmodelname
    using (@Html.BeginForm("CreateBlog", "controllername")){
    example ==> "@Html.TextBoxFor(x=>x.ID);"

<input type="submit" value="Create" class="btn btn-default" />
    }

    public ActionResult CreateBlog(yourmodelname model)
        {
               example==>int woNumber = model.ID;

        }
0
public ActionResult CreateBlog(FormCollection form)
    {
       // Access via form["namelable"],form["namelable"] etc..          
    }

Here FormCollection will have all posted data to action ..

Kaushik Thanki
  • 2,906
  • 2
  • 18
  • 40
0

View

@{
    ViewBag.Title = "CreateNonStronglyBlog";
}

<h2>Create Non Strongly Blog</h2>

@using (Html.BeginForm("CreateBlog","blog")){
    @Html.Label("namelable", "Put your name here", new { @id = "name" })
    @Html.TextBox("txtname", "", new { @id = "txtName"})
    @Html.Label("urllable", "Put your Url here", new { @id = "url" })
    @Html.TextBox("txturl", "", new { @id = "txturl"})
    <input type="submit" value="Create" class="btn btn-default" />
}

Controller

Public ActionResult CreateBlog(blog model)
{
    //You will get all values in model
}

Note : All your textbox names should match your model Property names, otherwise you won't get value of that textBox

Ghanshyam Singh
  • 1,236
  • 2
  • 13
  • 24
0
public ActionResult CreateBlog()
    {
       //Access via Request["txtName"],Request["txturl"]           
    }
or

public ActionResult CreateBlog(string txtName, string txturl)
    {
       //We will get submitted texbox values in given paramers           
    }