1

I've read How to use Bind Prefix?

but, here is my code and it doesn't work. the controller name is: "UserInfo.user_name"

 public JsonResult UniqueUserName([Bind(Prefix="UserInfo")] string user_name)
    {//user_name == null ?!?}

Thank's

UPDATE

adding my view:

 @Html.EditorFor(x => x.UserInfo)

and this is the EditorTemplate:

<div>
            @Html.LabelFor(m => m.user_name)
            @Html.TextBoxFor(m => m.user_name, new { required = true})
            @Html.ValidationMessage("user_name", new { @class = "error"})
        </div>

this is the model: I've removed from here more properties and more class since it makes no difference.

public class Info
{       
    [DisplayName("User Name")]
    [Required]
    [Remote("UniqueUserName", "Create")]
    public string user_name { set; get; }

}

public class EvalInfo
{        
    public Info UserInfo { set; get; }
    public EvalInfo()
    {
        UserInfo = new Info();
    }
}
Community
  • 1
  • 1
eyalewin
  • 360
  • 4
  • 20
  • 1
    http://stackoverflow.com/questions/5611262/how-to-define-form-field-prefix-in-asp-net-mvc/5611342#5611342 – Mohammed Swillam Mar 31 '14 at 14:24
  • nope. no success :( i put it in the GET action, and debugged, the HtmlFieldPrefix is filled with "UserInfo". the JsonResult is called by Remote DataAnnotation Attribute (Not a POST) and the user_name Property is null... – eyalewin Apr 01 '14 at 05:16

1 Answers1

1

Only in your view if your model is rendered with UserInfo_user_name then you can use your Bind. I advice you to read BindAttribute. Let's say in your view there is some ambiguity with two properties. then you can use your bind. And I think you can use it with a model. if your controller name is UserInfo.user_name it doesn't matter. what is matter is the model. I think if we see your view we can get some important info. Hope after reading the link it will help you.

try this:

    `
 public JsonResult UniqueUserName([Bind(Prefix="UserInfo")] Info info)
     {
        //and retreive your user_name via the model info 
    }

` I hope it will help you.

  • Could you see if what is the object called when your remote call is done. Just press F12 at your navigator, and then 'Network tab'. or what you can check the name of the id the source of the page and match it with the parameter in your remote Action –  Apr 01 '14 at 09:47
  • 1
    This is my requestURL: http://localhost:50798/Create/UniqueUserName?UserInfo.user_name=mo. and this is exactly what i wrote on my first question. – eyalewin Apr 01 '14 at 11:32